core
core copied to clipboard
Invalid type for Parameter::$schema according to phpstan
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