False positive (OneObjectOperatorPerLine) for property access within a class #53
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.
When I have something like this:
Then I expect no error from the OneObjectOperatorPerLineSniff to occur,
But I got
Only one object operator per line.
at line 13 (return $this->group->id;
).The error is triggered in
Line 113
. It occurs because$this->
is counted as first Object Operator. InhandleTwoObjectOperators
this case is excluded by the$isOwnCall
which tracks whether the starting point is$this
.I would suggest to do the same in
handleExcludedFluentInterfaces
. I adjusted at a little bit (because we can have more than 1 callerTokens).For explanation let's have a look at three examples:
$this->group->id
(which should raise no error),$user->group->id
(which should raise an error) and$this->user->group->id
(which should also raise an error):$callerTokens
(simplified)count($callerTokens)
$isOwnCall
$this->group->id
['group']
1
true
$user->group->id
['group']
1
false
$this->user->group->id
['user', 'group']
2
true
This could be handled by the following check: