Skip to content

Migrate to PHPCSUtils#360

Merged
sirbrillig merged 16 commits intotrunkfrom
3.x
Apr 21, 2026
Merged

Migrate to PHPCSUtils#360
sirbrillig merged 16 commits intotrunkfrom
3.x

Conversation

@sirbrillig
Copy link
Copy Markdown
Owner

@sirbrillig sirbrillig commented Jan 25, 2026

It's been many years since it was suggested to use PHPCSUtils to simplify the helpers used by this sniff (see discussion in #214 and #149 and #132 and probably others).

Originally I had held off because PHPCSUtils had not stabilized, but it is definitely stable now.

I've finally decided to try the migration to see what benefits it could provide.

This PR is the first step in that process that should eventually lead to 3.0.

Warning

Do not merge this into the 2.x branch! It changes the minimum supported versions of phpcs and adds a new dependency!

@sirbrillig sirbrillig changed the base branch from 2.x to trunk January 26, 2026 01:01
…ion()

Delegates condition checking to PHPCSUtils which provides the same
logic with an added isset($tokens[$ptr]) guard.
…:getParameters()

Delegates to PHPCSUtils which already parses all parameter attributes
including property_visibility for constructor-promoted parameters.
Also picks up PHP 8.4 asymmetric visibility (set_visibility_token) for
free. Removes the now-unused isTokenPartOfTypehint() and
isTokenPossiblyPartOfTypehint() helpers.
…getParameters()

Delegates argument parsing to PHPCSUtils which handles named params
(PHP 8+), closures, attributes, and has internal caching. Updates
getVariablesInsideCompact() and processVariableAsPassByReferenceFunctionCall()
to work with the PassedParameters ['start','end'] format; argument
positions are now 1-based integers matching PHPCSUtils conventions.
Removes stale Psalm baseline entries for the deleted $closePtr code.
Replaces the manual findPrevious call with an exclusion list with the
existing findContainingOpeningBracket() abstraction, and simplifies the
second findPrevious to skip only empty tokens.
@sirbrillig
Copy link
Copy Markdown
Owner Author

sirbrillig commented Apr 20, 2026

Benchmarks at the moment show that on a complex 4317 line file, 2.x takes approximately 1.864 seconds and 3.x takes 888.6 milliseconds! That's more than twice as fast.

2.x

  Time (mean ± σ):      1.864 s ±  0.047 s    [User: 1.465 s, System: 0.369 s]
  Range (min … max):    1.810 s …  1.943 s    10 runs

3.x

  Time (mean ± σ):     888.6 ms ±  38.1 ms    [User: 807.1 ms, System: 57.6 ms]
  Range (min … max):   845.0 ms … 963.2 ms    10 runs

@sirbrillig sirbrillig merged commit 32f0eda into trunk Apr 21, 2026
66 checks passed
@sirbrillig sirbrillig deleted the 3.x branch April 21, 2026 15:16
@sirbrillig
Copy link
Copy Markdown
Owner Author

Merged this into a new trunk branch, which will be the source for active development from here on. I released v3.0.0-beta.9 to try it out.

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