chore: raise PHPStan to level 10 - #135
Merged
Merged
Conversation
Level 10 is the last one — it treats implicit `mixed` the same way level 9 treats explicit `mixed`. All 17 errors were the same shape: reading back through Nette's magic accessors, which are typed `mixed` by nature. Nine of them were the `$el->class[] = '...'` idiom, spread across seven files, each preceded (or not) by its own `standardizeClass()` call. That is now one place: `BootstrapUtils` grew `fetchClasses()`, `addClass()`, `removeClass()` and `hasClass()`, and the call sites say what they mean. `BootstrapRenderer::fetchClasses()`, added at level 9, was the same logic again and now delegates to the util. The rest: - `BootstrapForm::setAjax()` used the same class juggling by hand; it now goes through the util and keeps its "only add if absent" behaviour. - The `onError` handler took an untyped `$form` with the type in a docblock that PHPStan could not attach. It is a real parameter type now. - `renderBegin()` read `$el->action` three times, casting `mixed` to string. It reads the attribute once into a local and normalizes it there, which also covers an action set as a `Nette\Application\UI\Link`. - `addInputError()` called `addError()` on whatever `getComponent()` returned. It now says what it needs, and explains itself when given a component that cannot hold an error (a container, say) instead of dying on an undefined method. `UploadInput` also loses a `trim($control->class .= ...)`, which relied on the class attribute being a string and on `.=` inside a function call. Rendered HTML is unchanged — no fixture updates. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #135 +/- ##
============================================
+ Coverage 97.51% 97.54% +0.02%
- Complexity 333 340 +7
============================================
Files 25 25
Lines 1007 1019 +12
============================================
+ Hits 982 994 +12
Misses 25 25 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Follow-up to #134, and the last step — 10 is PHPStan's maximum level. It treats implicit
mixedthe same way level 9 treats explicitmixed.All 17 errors had the same origin: reading back through Nette's magic accessors, which are
mixedby nature.The
class[]idiom, in one placeNine of the errors were
$el->class[] = '...'— spread across seven files, each preceded (or, in two cases, not preceded) by its ownBootstrapUtils::standardizeClass()call. It worked because Nette'sHtml::__get()returns by reference, so the append auto-vivified the attribute.BootstrapUtilsnow carries that knowledge instead:Call sites now read as what they do.
BootstrapRenderer::fetchClasses(), which #134 added, was this same logic a second time and now delegates to the util.standardizeClass()is kept — it is public API — though nothing insrc/needs it any more.The rest
BootstrapForm::setAjax()did the class juggling by hand (standardizeClass→ read →in_array→array_diff→ write back). It goes through the util now and keeps its "only add if absent" behaviour, which a new test pins down.onErrorhandler took an untyped$formwith@param BootstrapForm $formin a docblock positioned where PHPStan could not attach it. It is a real parameter type now.renderBegin()read$el->actionthree times, castingmixedto string and carrying two@noinspectioncomments. It reads the attribute once into a local and normalizes it there — which also handles an action set as aNette\Application\UI\Linkrather than a plain string.addInputError()calledaddError()on whatevergetComponent()returned. It now checks for aBaseControland throwsInvalidArgumentExceptionnaming the component when given something that cannot hold an error (a container, say), instead of dying on an undefined method.UploadInputlosestrim($control->class .= ...), which relied on the class attribute being a string and on.=evaluated inside a function call.Verification
make phpstan(now-l 10, the maximum) — no errorsmake cs— cleanmake tests— 181 tests, 277 assertions, all passing8 new tests: six cover the new
BootstrapUtilsmethods (both attribute shapes, absent attribute, removing a class that is not there), one thatsetAjax(true)twice does not duplicate the class, one for theaddInputErrorguard.Rendered HTML is unchanged — no fixture updates. The snapshot suite is the safety net for the
class[]refactor: every one of those seven files feeds into fixtures that still match byte for byte.🤖 Generated with Claude Code