Skip to content

Invalid type for Parameter::$schema according to phpstan #7119

Open
@nesl247

Description

@nesl247

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

phpstan/phpstan#11300
phpstan/phpstan#8438

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions