Skip to content

Commit 5cd7e98

Browse files
committed
More guards
1 parent a600002 commit 5cd7e98

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

src/MCP/MCPConfig.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ class MCPConfig {
1818
* @return non-falsy-string
1919
*/
2020
public static function get_namespace(): string {
21-
$namespace = (string) \apply_filters(
21+
$namespace = \apply_filters(
2222
'saltus/framework/mcp/namespace',
2323
'saltus-framework/v1'
2424
);
25+
if ( ! is_string( $namespace ) || trim( $namespace ) === '' ) {
26+
return 'saltus-framework/v1';
27+
}
2528
/** @var non-falsy-string */
26-
return $namespace !== '' ? $namespace : 'saltus-framework/v1';
29+
return trim( $namespace );
2730
}
2831

2932
/**
@@ -45,13 +48,23 @@ public static function get_ability_category(): array {
4548
'description' => 'Saltus Framework content modeling and administration abilities.',
4649
];
4750

48-
/** @var array{id: string, label: string, description: string} */
49-
$filtered = (array) \apply_filters(
51+
$filtered = \apply_filters(
5052
'saltus/framework/mcp/ability_category',
5153
$default
5254
);
5355

54-
return array_merge( $default, $filtered );
56+
if ( ! is_array( $filtered ) ) {
57+
return $default;
58+
}
59+
60+
$sanitized = [];
61+
foreach ( [ 'id', 'label', 'description' ] as $key ) {
62+
$val = $filtered[ $key ] ?? null;
63+
$sanitized[ $key ] = is_string( $val ) ? $val : $default[ $key ];
64+
}
65+
66+
/** @var array{id: string, label: string, description: string} */
67+
return $sanitized;
5568
}
5669

5770
/**
@@ -62,9 +75,13 @@ public static function get_ability_category(): array {
6275
* @return string
6376
*/
6477
public static function get_ability_prefix(): string {
65-
return (string) \apply_filters(
78+
$prefix = \apply_filters(
6679
'saltus/framework/mcp/ability_prefix',
6780
'saltus/'
6881
);
82+
if ( ! is_string( $prefix ) ) {
83+
return 'saltus/';
84+
}
85+
return $prefix;
6986
}
7087
}

0 commit comments

Comments
 (0)