core icon indicating copy to clipboard operation
core copied to clipboard

Invalid type for Parameter::$schema according to phpstan

Open nesl247 opened this issue 8 months ago • 0 comments

API Platform version(s) affected: 4.1.7

Description
Phpstan complains that the type set for the $schema is invalid in the class Parameter. The problem is that phpstan does not support unions of array shapes. Thus anyone trying to use fields other than type or default in their array will get an error.

@param (array<string, mixed>&array{type?: string, default?: string})|null $schema
phpstan: Parameter $schema of class ApiPlatform\Metadata\QueryParameter constructor expects array{type?: string, default?: string}|null, array{type: 'integer', min: 1, default: 1} given.

How to reproduce

new QueryParameter(key: 'page', schema: ['type' => 'integer', 'min' => 1, 'default' => 1], constraints: [new Type('numeric'), new GreaterThanOrEqual(1)]),

Possible Solution

Additional Context

https://github.com/phpstan/phpstan/issues/11300 https://github.com/phpstan/phpstan/issues/8438

nesl247 avatar May 02 '25 17:05 nesl247