Skip to content

Commit d050a2b

Browse files
committed
fix: use array lookup instead of match for PHP 7.4 compat
Replace match expressions (PHP 8.0+) with associative array lookups in resolve_show_in_mcp and resolve_show_in_rest. Restores PHP 7.4 compatibility and reduces cyclomatic complexity below the PHPCS threshold of 10.
1 parent 32209fe commit d050a2b

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

src/MCP/McpPolicy.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ public function is_enabled( Model $model, string $capability ): bool {
5252
* @param array<string, mixed> $config
5353
*/
5454
private function resolve_show_in_mcp( array $config, string $capability ): bool {
55-
$section = match ( $capability ) {
55+
$map = [
5656
ModelRestPolicy::CAPABILITY_META => $config['meta'] ?? null,
5757
ModelRestPolicy::CAPABILITY_SETTINGS => $config['settings'] ?? null,
5858
ModelRestPolicy::CAPABILITY_DUPLICATE => $config['features']['duplicate'] ?? null,
5959
ModelRestPolicy::CAPABILITY_EXPORT => $config['features']['single_export'] ?? null,
6060
ModelRestPolicy::CAPABILITY_REORDER => $config['features']['drag_and_drop'] ?? null,
61-
default => null,
62-
};
61+
];
6362

63+
$section = $map[ $capability ] ?? null;
6464
if ( $section === null ) {
6565
return false;
6666
}
@@ -73,7 +73,7 @@ private function resolve_show_in_mcp( array $config, string $capability ): bool
7373
}
7474

7575
/**
76-
* @param Model $model
76+
* @param string $name
7777
*/
7878
public function get_model( string $name ): ?Model {
7979
$models = $this->modeler->get_models();

src/Rest/ModelRestPolicy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public function is_enabled( Model $model, string $capability ): bool {
5959
* @param array<string, mixed> $config
6060
*/
6161
private function resolve_show_in_rest( array $config, string $capability ): bool {
62-
$section = match ( $capability ) {
62+
$map = [
6363
self::CAPABILITY_META => $config['meta'] ?? null,
6464
self::CAPABILITY_SETTINGS => $config['settings'] ?? null,
6565
self::CAPABILITY_DUPLICATE => $config['features']['duplicate'] ?? null,
6666
self::CAPABILITY_EXPORT => $config['features']['single_export'] ?? null,
6767
self::CAPABILITY_REORDER => $config['features']['drag_and_drop'] ?? null,
68-
default => null,
69-
};
68+
];
7069

70+
$section = $map[ $capability ] ?? null;
7171
if ( $section === null ) {
7272
return false;
7373
}

0 commit comments

Comments
 (0)