Skip to content

Checks on array keys arent added to the type information #2911

@BackEndTea

Description

@BackEndTea

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/db3495e0-2cc4-4acb-ba04-ce742258680a

A smaller variant of the original snippet:
https://phpstan.org/r/e2636992-cccb-46db-9f06-56a4e34c0855

Output:

+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Line | test.php                                                                                                                                           |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
| 64   | Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>. |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------+

Expected output

I would expect no issue, as within the method i make sure the two keys are the correct value.

The array merge makes sure the keys exist are there. Since it is a const the keys are (should) be known to phpstan. The rest of the method asserts they are correct.

I would've expected phpstan to add the new information of the shape of the array to the type system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions