Skip to content

phpstan: lvl 1 -> 2 #1854

Merged
ostrolucky merged 1 commit into2.13.xfrom
phpstan-lvl2
Jan 14, 2025
Merged

phpstan: lvl 1 -> 2 #1854
ostrolucky merged 1 commit into2.13.xfrom
phpstan-lvl2

Conversation

@ostrolucky
Copy link
Member

No description provided.

path: src/DataCollector/DoctrineDataCollector.php
# Probably needs Symfony plugin
- message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\Node#'
path: src/DependencyInjection/Configuration.php
Copy link
Member

Choose a reason for hiding this comment

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

How do you make the choice to user ignoreErrors vs phpstan-ignore? Now that phpstan-ignore comes with error identifier, I think it's good.

Copy link
Member Author

Choose a reason for hiding this comment

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

This rule suppresses 10 violations. It's hard to make a hard rule out of it, but 10 violations of same kind I would say are sufficient. Once we solve underlying issue (like here, maybe it will be solved by symfony plugin), we can remove it from one place instead of hunting it all over. If it was like 3 violations, I would be more inclined to do it inline. But anything in between is subjective.

Copy link
Member

Choose a reason for hiding this comment

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

Now that phpstan-ignore comes with error identifier

We can use those identifiers in the ignore rules of our neon file as well and we should probably do that.

Copy link
Member

Choose a reason for hiding this comment

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

To elaborate, in the past I thought the baseline approach was superior, because using @phpstan-ignore-next-line could hide more than the intended errors. Now that it's possible to do that directly in the code, I think it might be nicer to have the ignore rules close to the code, because sometimes I'm wondering why PHPStan "isn't working". Also, if you see an existing ignore rule in the code, you are more likely to challenge it, if you know how to properly fix it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes normally I prefer inline suppressions (and ask people to do it). There are bunch of issues that prevent us to do it efficiently unfortunately, for example it's not enough for phpstan to suppress missing class when instantiating it, phpstan is not smart enough to understand that if you ignore missing class it's also ok to ignore method calls on such class. So now you have to sprinkle code with suppressions each time such class is used as well. I would expect I can just suppress instantiating class that can be missing, instead of having to suppress dozens of other issues cascading from that as well.

@ostrolucky ostrolucky merged commit 92d19dc into 2.13.x Jan 14, 2025
15 checks passed
@derrabus derrabus deleted the phpstan-lvl2 branch January 14, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants