Skip to content

[perf] Speed up ArrayToFirstClassCallableRector with cheap count and attribute guards before ScopeFetcher - #8796

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
alfredbez:fix/rector-perf-array-to-first-class-callable-guard
Oct 23, 2026
Merged

TomasVotruba merged 1 commit into
rectorphp:mainfrom
alfredbez:fix/rector-perf-array-to-first-class-callable-guard

Conversation

@alfredbez

Copy link
Copy Markdown
Contributor

In ArrayToFirstClassCallableRector, refactor() fetched the node's scope via ScopeFetcher::fetch($node) for every array before verifying that the array contains exactly two items, and before checking whether the array is a class constant value, default property value, parameter default, or unpacked argument. For non-callable arrays, scope resolution was performed unnecessarily.

Reproducer

class Subject
{
    public const DEFAULT_ITEMS = ['a', 'b', 'c'];

    public function run(): void
    {
        $single = ['item'];
        $triple = [1, 2, 3];
    }
}

Expected Behavior

ArrayToFirstClassCallableRector should verify that the array contains exactly two items and check attribute guards before calling ScopeFetcher::fetch($node). Non-callable arrays should be rejected early without resolving scope.

@TomasVotruba

Copy link
Copy Markdown
Member

Thanks 👍

@TomasVotruba
TomasVotruba merged commit dd99e41 into rectorphp:main Oct 23, 2026
48 of 49 checks passed
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.

2 participants