Skip to content

PHPStan level 2#1179

Merged
mkalkbrenner merged 3 commits intosolariumphp:masterfrom
thomascorthals:phpstan
Mar 19, 2026
Merged

PHPStan level 2#1179
mkalkbrenner merged 3 commits intosolariumphp:masterfrom
thomascorthals:phpstan

Conversation

@thomascorthals
Copy link
Member

Gave it a go to get the codebased analysed at PHPStan level 2. It shouldn't have BC breaks since the examples keep running without any changes. Unit and integration tests also keep running, changes in their code are just to get them to level 2 as well. I still prefer to have this coincide with a new major release though.

I set out with the idea that I didn't want an ignoreErrors section in the config. The very few things that do need ignoring are marked right in the code with an explanation why. E.g.:

// @phpstan-ignore method.deprecated (we're calling a deprecated method on purpose)

The bulk of the changes comes down to typehinting. Some of it can be fixed with corrected or more accurate typehints in method signatures. But there are numerous places where that wasn't possible because you can't narrow a parameter type in a child class. For instance, if an abstract parent method has an AbstractComponent $component parameter, the statical analysis doesn't "know" the object type in an overriding child method and you can't have a narrower type in the method signature. Annotating it as @param AbstractComponent&AnalyticsComponent in PHPDoc works around this limitation. The parser doesn't care, the human knows what is meant, PHPStan interprets it intuitively. If I'm missing something here and there's a better way around this contravariance limitation, let me know!

Where it made sense in tests, I went with assertInstanceOf() instead of typehint annotations because that also narrows down the type for PHPStan.

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 99.09091% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.40%. Comparing base (33ce9c3) to head (00ea0cb).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/Component/ResponseParser/FacetSet.php 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1179      +/-   ##
==========================================
+ Coverage   98.21%   98.40%   +0.18%     
==========================================
  Files         404      403       -1     
  Lines       10647    10646       -1     
==========================================
+ Hits        10457    10476      +19     
+ Misses        190      170      -20     
Flag Coverage Δ
unittests 98.40% <99.09%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mkalkbrenner mkalkbrenner merged commit 71fd796 into solariumphp:master Mar 19, 2026
44 checks passed
@thomascorthals thomascorthals deleted the phpstan branch March 19, 2026 19:44
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.

2 participants