LatteTags: Fix PHPStan error with nette/forms < 3.3#21
Open
jtojnar wants to merge 9 commits into
Open
Conversation
jtojnar
commented
Jul 14, 2026
Contributor
- phpstan: Ignore temp files
- LatteTags: Fix PHPStan error with nette/forms < 3.3
Member
|
I'm totally ok with dropping PHP 8.0. |
PHPStan 2 would raise `argument.type` error:
Parameter nextras#2 $haystack of function in_array expects array, mixed given.
It should still work but PHPStan would get angry:
Error: Property Nette\Forms\Rendering\DefaultFormRenderer::$form (Nette\Forms\Form) in isset() is not nullable.
Error: Property Nette\Forms\Rendering\DefaultFormRenderer::$form (Nette\Forms\Form) in isset() is not nullable.
Error: Parameter nextras#1 $object_or_class of function method_exists expects object|string, mixed given.
Error: Cannot call method getLabelPrototype() on class-string|object.
Error: Property Nette\Forms\Rendering\DefaultFormRenderer::$form (Nette\Forms\Form) in isset() is not nullable.
Error: Parameter nextras#1 $object_or_class of function method_exists expects object|string, mixed given.
Error: Cannot call method getControlPrototype() on class-string|object.
Error: Cannot call method getControlPrototype() on class-string|object.
Error: Cannot call method getLabelPrototype() on class-string|object.
Likely because on PHP 8.0 we need to use `nette/forms` 3.1.15 rather than 3.2.9 used by PHP 8.1, and the former uses PHPDoc instead of property type hints:
https://github.com/nette/forms/blob/v3.1.15/src/Forms/Rendering/DefaultFormRenderer.php#L121
And we do not want to bother fixing it.
This will satisfy PHPStan 2. While it is not guaranteed that the methods will return `Html`, any reasonable control implementation probably does that.
`phpstan/phpstan-nette` registers `PropertyReflection` for `Html` class that changes property types to `mixed`: https://github.com/phpstan/phpstan-nette/blob/2.0.12/src/Reflection/Nette/HtmlPropertyReflection.php#L21 This seems to take precedence over the upstream `@property` PHPDoc annotations: nette/utils@52d7e1b As a result, PHPStan would complain: Parameter nextras#1 $child of method Nette\Utils\Html::addHtml() expects Nette\HtmlStringable|string, mixed given.
Similarly to in previous commit, `phpstan/phpstan-nette` changes virtual property types to `mixed`. As a result, PHPStan would complain:
Binary operation "." between mixed and '-inline' results in an error.
PHPStan 2 will consider the `property_exists` check always true so we need to ignore it.
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.