Skip to content

[TypeDeclaration] Skip recursive dim fetch closure in StrictArrayParamDimFetchRector#8141

Closed
TomasVotruba wants to merge 1 commit into
mainfrom
skip-recursive-dim-fetch-closure
Closed

[TypeDeclaration] Skip recursive dim fetch closure in StrictArrayParamDimFetchRector#8141
TomasVotruba wants to merge 1 commit into
mainfrom
skip-recursive-dim-fetch-closure

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Reproducer

StrictArrayParamDimFetchRector gives a false positive on recursive closures that walk an ArrayAccess tree (real case: Symfony FormView in Mautic's FormThemeTrait):

$findThemes = function ($form, $formView) use (&$findThemes): void {
    foreach ($form as $name => $field) {
        $fieldView = $formView[$name];       // $formView is a FormView (ArrayAccess), not array
        $findThemes($field, $fieldView);      // element fed back as the same param
    }
};

$findThemes($form, $formView);

The rule added array $formView, which is wrong — FormView implements ArrayAccess.

Why it happens

The closure param $formView is untyped, so PHPStan sees mixed inside the closure; the only proof it is a FormView lives at the call site, which the rule does not inspect. Seeing just $formView[$name], the rule assumes array.

Fix

Skip when a value read from $param[dim] (directly, or via a variable assigned from it) is fed back as an argument into the same closure/function (recursion — detected via the closure's by-ref use self-reference or a function's own name). Using an element as the container again is a strong tell for an ArrayAccess tree, not a plain array.

Conservative: only this recursive-feed shape is skipped; the existing changing fixtures are unaffected.

…mDimFetchRector

A closure that feeds a value read from $param[dim] back into itself as the same
argument signals an ArrayAccess tree (e.g. Symfony FormView), not a plain array.
Adding an 'array' type hint there is a false positive.
@TomasVotruba TomasVotruba deleted the skip-recursive-dim-fetch-closure branch July 4, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant