Skip to content

Fix phpstan magento2 narrowed type#4243

Merged
antonmedv merged 2 commits into
deployphp:masterfrom
poespas:fix-phpstan-magento2-narrowed-type
Jul 13, 2026
Merged

Fix phpstan magento2 narrowed type#4243
antonmedv merged 2 commits into
deployphp:masterfrom
poespas:fix-phpstan-magento2-narrowed-type

Conversation

@poespas

@poespas poespas commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

phpstan 2.2.3 (released June 30) extended the alreadyNarrowedType check to flag always-true in_array(..., true) calls when the needle is a finite union fully covered by the haystack. Since CI installs the latest phpstan on every run (no composer.lock), master now fails the check workflow - and so does every PR branched from it, even without touching the affected code (example run).

The offender is magentoDeployAssetsSplit() in recipe/magento2.php: the @phpstan-param 'frontend'|'backend' $area docblock narrows the needle so the runtime in_array() guard looks always true. But callers can pass any string, so the guard is the part worth keeping - this PR drops the docblock narrowing instead. Setting treatPhpDocTypesAsCertain: false would also silence it, but that changes analysis repo-wide for one false positive.

  • Bug fix #…?

  • New feature?

  • BC breaks?

  • Tests added?

  • Docs added?

    Please, regenerate docs by running next command:
    $ php bin/docgen
    

Jonathan Visser added 2 commits July 13, 2026 15:01
The @phpstan-param docblock narrowed $area to 'frontend'|'backend',
making the runtime in_array() guard always true according to phpstan
2.2.3. The runtime check is intentional since callers can pass any
string, so drop the docblock narrowing instead of the check.
@antonmedv antonmedv merged commit 453cca8 into deployphp:master Jul 13, 2026
9 checks passed
@poespas poespas deleted the fix-phpstan-magento2-narrowed-type branch July 13, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants