Skip to content

Fix error reported on the wrong line#4991

Merged
VincentLanglet merged 11 commits intophpstan:2.1.xfrom
VincentLanglet:fixErrorLine
Feb 19, 2026
Merged

Fix error reported on the wrong line#4991
VincentLanglet merged 11 commits intophpstan:2.1.xfrom
VincentLanglet:fixErrorLine

Conversation

@VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented Feb 18, 2026

@phpstan-bot
Copy link
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@VincentLanglet
Copy link
Contributor Author

The failure on phpstan-doctrine seems legit since now it's report on getQuery and not on the start of the line
https://github.com/phpstan/phpstan-doctrine/blob/734ef36c2709b51943f04aacadddb76f239562d3/tests/Rules/Doctrine/ORM/data/query-builder-dynamic.php#L43

But maybe this behavior (and the initial PR #4967) should be behind bleedingEdge ?

@VincentLanglet VincentLanglet marked this pull request as ready for review February 18, 2026 19:47
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

} else {
$funcCallLine = $funcCall->getStartLine();
}
$funcCallLine = RuleErrorTransformer::getStartLineFromNode($funcCall);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this line?

Copy link
Contributor Author

@VincentLanglet VincentLanglet Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because

  • I compute the line from the node only if it's not set and this Check set the line.
  • If I remove the ->line(...) calls, since the AttributesCheck calls the functionCallParametersCheck with another Node than the one from the ClassAttributesRule it makes a test from ClassAttributesRuleTest to fail.

Comment on lines 78 to 79
} else {
$line = self::getStartLineFromNode($node);
Copy link
Contributor

@staabm staabm Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had a look thru the codebase.

we have already PhpDocLineHelper::detectLine() which is called like line(PhpDocLineHelper::detectLine($node, $phpDocTag)) .

this makes me think we should not have this special fallback case here, but call something like NodeChainLineHelper::detectLine($node) right at the ErrorBuilder call-sites where ->line() is invoked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes me think we should not have this special fallback case here, but call something like NodeChainLineHelper::detectLine($node) right at the ErrorBuilder call-sites where ->line() is invoked.

Lot of existing rules are not calling line() and rely on the defaut fallback which was already implemented in RuleErrortransformer $node->getStartLine().

There is tons of rule to fix, so it would be easier to modify the fallback.

Even binary operator are wrong
https://phpstan.org/r/090b54c3-0255-4027-9934-491d8ab962b7

And yes PipeOperator has the same issue too https://phpstan.org/r/7ab46b15-18c9-4d5b-bfc9-27bc78efe3d4

But there is so much to fix, I feel like we should first:

  • validate a strategy with ondrej
  • Fix/Implement it, step by step

I start to feel like we should fix rules one by one...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree - thanks for looking into it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried another strategy with af0f984

I feel like it's safer to avoid a general strategy in RuleTransformer and instead to fix rules one by one. WDYT ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, thats what I had in mind with my comment

@VincentLanglet VincentLanglet marked this pull request as draft February 19, 2026 09:48
@VincentLanglet VincentLanglet marked this pull request as ready for review February 19, 2026 11:52
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@VincentLanglet
Copy link
Contributor Author

I think it can be merged like this.

I focused on method and properties.

Copy link
Contributor

@staabm staabm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this looks really good

@VincentLanglet VincentLanglet merged commit 45a62ae into phpstan:2.1.x Feb 19, 2026
641 of 646 checks passed
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.

3 participants

Comments