PHPStan level 9

This commit is contained in:
Pascal Birchler 2025-04-24 15:49:34 +02:00
parent 2488e47ea7
commit b6835d0173
No known key found for this signature in database
GPG key ID: 0DECE73DD74E8B2F
2 changed files with 7 additions and 3 deletions

View file

@ -1,5 +1,5 @@
parameters:
level: 8
level: 9
paths:
- mcp.php
- src/

View file

@ -12,6 +12,7 @@ use WP_REST_Response;
* REST API tools class.
*
* @phpstan-import-type ToolDefinition from Server
* @phpstan-type ArgumentSchema array{description?: string, type?: string, required?: bool}
*/
readonly class RestApi {
private LoggerInterface $logger;
@ -156,7 +157,8 @@ readonly class RestApi {
if ( array_key_exists( $match, $params ) ) {
$route = (string) preg_replace(
'/(\(\?P<' . $match . '>.*?\))/',
$params[ $match ],
// @phpstan-ignore cast.string
(string) $params[ $match ],
$route,
1
);
@ -206,6 +208,7 @@ readonly class RestApi {
* @throws \Exception
*
* @param array<string, mixed> $args REST API route arguments.
* @phpstan-param array<string, ArgumentSchema> $args REST API route arguments.
* @return array<string, mixed> Normalized schema.
*/
private function args_to_schema( array $args = [] ): array {
@ -269,7 +272,8 @@ readonly class RestApi {
}

if ( ! \is_array( $type ) ) {
throw new \Exception( 'Invalid type: ' . $type );
// @phpstan-ignore binaryOp.invalid
throw new \Exception( 'Invalid type: ' . $type);
}

// Find valid values in array.