Open
Conversation
Detects method chains where multiple ->method() or ?->method() calls appear on the same line. Each call in a chain must be on its own line. - Registers on CallLike, handles both MethodCall and NullsafeMethodCall - Compares method name start lines to correctly handle multiline expressions - Reports errors at the method name line via RuleErrorBuilder::line() - Not registered in rules.neon — enabled per-module in consumer projects Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Split nullsafe operator (?->) test fixtures into separate files conditionally loaded on PHP >= 8.0, since PHP 7.4 cannot parse that syntax. Add return type ignore for PHPStan 1.x compatibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Allow method chains inside string interpolation, skipping error detection for such cases. Adds caching of file contents for efficient parsing and extends the node type handling in the rule.
f9d1643 to
b5c5ea0
Compare
…ineRule A method call without arguments (e.g. ->relation()) is treated like a property access and does not count as "a thing". This allows patterns like $item->magnaPure()->associate($x) on a single line. Also excludes method chains inside string interpolation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
b5c5ea0 to
9175bf9
Compare
The previous cleanup accidentally removed the php-below-8.0.neon inclusion and the OneThingPerLineRule return type ignore for older PHPStan versions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
spawnia
reviewed
Feb 23, 2026
|
|
||
| public function getNodeType(): string | ||
| { | ||
| return CallLike::class; |
Member
There was a problem hiding this comment.
Eine lange Kette von Property-Zugriffen würde für mich auch unter OneThingPerLine fallen, ist aber nicht CallLike. PHPStan Regeln gehen aber immer nur auf einen NodeType, oder? Daher würde ich den Klassennamen spezifischer wählen. Den Identifier mll.oneThingPerLine finde ich in Ordnung, den könnten wir in mehreren Klassen mit verschiedener Message verwenden.
Comment on lines
+76
to
+83
| $startPos = $root->getStartFilePos(); | ||
| if ($startPos <= 0) { | ||
| return false; | ||
| } | ||
|
|
||
| $this->fileContentsCache[$file] ??= file_get_contents($file); | ||
|
|
||
| return $this->fileContentsCache[$file][$startPos - 1] === '{'; |
Member
There was a problem hiding this comment.
Können wir nochmal evaluieren ob das anders geht, auf AST Ebene? Mir fallen einige Edge-Cases ein in denen das so implementiert nicht passt:
if ($cond) {$bar = 123;} // false-positive
return "bar is $bar"; // false-negative
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.
Summary
OneThingPerLineRulePHPStan rule that detects method chains where multiple->method()or?->method()calls appear on the same linerules.neon— intended to be enabled per-module in consumer projects (like limes-api)Rule details
Identifier:
mll.oneThingPerLineTest plan
makepasses (rector, php-cs-fixer, phpstan, phpunit)?->/->, multiline args, chains inside closures, chains as arguments🤖 Generated with Claude Code