fix(NO-TASK): Make SlowOrderBy work and open the PHP target - #45
Open
aaronware wants to merge 1 commit into
Open
fix(NO-TASK): Make SlowOrderBy work and open the PHP target#45aaronware wants to merge 1 commit into
aaronware wants to merge 1 commit into
Conversation
SlowOrderBySniff has never worked, for two independent reasons. It called `$this->addMessage()`, the shape WPCS 2 offered on WordPressCS\WordPress\Sniff. WPCS 3 removed it, so the call resolved to nothing on the sniff or its parent and the sniff fatalled the moment it found something to report - "Call to undefined method Linchpin\Sniffs\Performance\SlowOrderBySniff::addMessage()". SlowMetaQuerySniff hit the same wall and grew a MessageHelper shim; this one never did, so consuming projects excluded it outright. linchpin.com carries exactly that exclusion. And it could not have matched anything anyway. The parent builds the value from raw tokens, so a literal arrives as `'rand'` with its quotes, and the switch compared against `rand`. Stripping the quotes is what makes the sniff actually fire. Rather than re-adding a shim, the callback now returns true and lets the parent emit. That is how AbstractArrayAssignmentRestrictionsSniff is designed to be used, and it drops the $stackPtr property and the process_token() override that existed only to carry a token pointer to the manual call - the parent reports against the key's own token, which is a more accurate position. The group message becomes %2$s because the parent passes `array( $key, $value )`, so %s is the literal "orderby" rather than the value worth naming. Verified against a fixture: three warnings for rand, meta_value and meta_value_num, each naming the value, and `date` correctly ignored. testVersion also becomes open-ended. A closed upper bound goes stale silently - it said 8.2-8.4 while linchpin.com had already moved to PHP 8.5, so PHPCompatibility was checking that project against the wrong target and the project had to override this line in its own ruleset to get correct results. "8.2-" means 8.2 and above. Note the package's own `composer test` is red on main already, before this change: the fixture tests fail to load the ruleset with "Class WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff not found". That is a harness autoloading problem, unrelated and untouched here.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linchpin.Performance.SlowOrderByhas never workedTwo independent reasons, either of which alone would have been enough.
1. It fatalled.
callback()called$this->addMessage()— the shape WPCS 2 offered onWordPressCS\WordPress\Sniff. WPCS 3 removed it, so the call resolved to nothing on the sniff or its parent:Because it only ran on a query that actually ordered by one of the slow values, it looked healthy on any codebase that never hit the pattern.
SlowMetaQuerySniffhit the same wall and grew aMessageHelpershim; this one never did, so consuming projects excluded it.linchpin.comcarries exactly that exclusion, referencing LINCHPIN-5245.2. It could never have matched.
AbstractArrayAssignmentRestrictionsSniffbuilds the value from raw tokens, so a literal arrives as'rand'— quotes included — and theswitchcompared againstrand. Stripping the quotes is what makes it fire at all.The fix
Rather than re-adding a shim,
callback()returnstrueand lets the parent emit. That's how the abstract class is designed to be used, and it drops the$stackPtrproperty and theprocess_token()override that existed only to carry a token pointer to the manual call — the parent reports against the key's own token, a more accurate position.The group message becomes
%2$s: the parent passesarray( $key, $value )as replacements, so%sresolves to the literal"orderby"rather than the value worth naming.Verified against a fixture:
…and
'date'correctly ignored.testVersionbecomes open-endedIt said
8.2-8.4whilelinchpin.comhad already moved to PHP 8.5 — so PHPCompatibility was checking that project against the wrong target, and the project had to override this line in its own ruleset to get correct results. A closed upper bound goes stale silently and needs a release here before any consumer can be checked correctly.8.2-means 8.2 and above; a project that wants to pin one version still can.Please note
composer testis already red onmain, before this change — the fixture tests fail to load the ruleset withClass "WordPressCS\WordPress\AbstractArrayAssignmentRestrictionsSniff" not found. That's a harness autoloading problem, unrelated to this and deliberately untouched. Worth a separate look, since it means the sniff tests aren't currently protecting anything.Downstream
Once released,
linchpin.comcan drop both itsLinchpin.Performance.SlowMetaQuery/SlowOrderByexclusions and its localtestVersionoverride.