Skip to content

PHPCS: Fix SprykerDisallowFunctions rule#104

Merged
mringler merged 2 commits intodevelopfrom
slow_phpcs
Feb 17, 2026
Merged

PHPCS: Fix SprykerDisallowFunctions rule#104
mringler merged 2 commits intodevelopfrom
slow_phpcs

Conversation

@mringler
Copy link
Copy Markdown
Collaborator

@mringler mringler commented Feb 17, 2026

PHPCS has been really slow, it takes about twice as long as usual. See for example this run of 1m 23s compared to this run of 2. 58s.

Turns out the rule Spryker.Internal.SprykerDisallowFunctions requires a PHP version or has to be turned off, otherwise it goes nuts. In the file, it just says:

 * Do not use functions that are not available for lowest version supported.
 * By default, only applies to core if no PHP version is passed in.

And looking at the code, "core" means Spryker core:

        if ($version === null && $this->isCore($phpcsFile)) {
            $version = static::PHP_MIN;
        }

and

    protected function isCore(File $phpCsFile): bool
    {
        $namespace = $this->getNamespace($phpCsFile);

        return strpos($namespace, static::NAMESPACE_SPRYKER) === 0;
    }

There are lots of string operations involved in getNamespace(), and I think those are run for every single token, causing the issue.

Similar problem with Spryker.Internal.SprykerPreferStaticOverSelf, now I kicked out all of them (except SprykerDisallowFunctions, which could be useful and is cheap when configured - 0.004s in Criteria).


The change to PHP version in SprykerDisallowFunctions should cause an error when functions from later PHP versions are used. So setting it to 8.1 would be wrong, since we are using symfony polyfills. However, there is no error when using array_first(), which was added in PHP 8.5. Don't know if the rule recognizes the polyfill? Does it even do anything? Maybe I should have just disabled it...

@mringler mringler merged commit 55d5066 into develop Feb 17, 2026
39 checks passed
@mringler mringler deleted the slow_phpcs branch February 17, 2026 15:06
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.

1 participant