Fix ci, deprecations, forms 3.3 support#21
Merged
Conversation
jtojnar
commented
Jul 14, 2026
Collaborator
- phpstan: Ignore temp files
- LatteTags: Fix PHPStan error with nette/forms < 3.3
Member
|
I'm totally ok with dropping PHP 8.0. |
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.
On PHP 8.1, PHPStan would complain:
Access to an undefined property Nextras\FormsRendering\LatteTags\LabelNode::$tagRanges.
We could add a `property_exists` for that as well but PHPStan 2 will consider at least one of the `property_exists` checks always true so we would need to ignore them. Also, since there can be some overlap where both properties exist, we cannot specify `count` of how many times the error should be ignored:
| PHP | latte | forms | count |
| 8.1 | 3.0.26| 3.2.9 | 1 |
| 8.2 | 3.1.4 | 3.2.9 | 2 |
| 8.3 | 3.1.4 | 3.3.0 | 1 |
But even with that, PHPStan 2 would complain on PHP 8.1:
Parameter nextras#1 $array of function end expects array|object, mixed given.
We could try to ignore that as well but that is painful since PHPStan would complain about stale ignore on PHP > 8.1, unless we wrote the config file in PHP and made the ignore conditional on `latte` version.
Let’s just lie to PHPStan using `@property` annotations and use `isset` to achieve the runtime functionality.
PHPStan 2 would raise `argument.type` error:
Parameter nextras#2 $haystack of function in_array expects array, mixed given.
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.
Without these, the examples will fail to start. Using the same pattern as nette/web-project@0eae660
Supported since 3.0.7: nette/application@d247113 Deprecated since 3.3.0: nette/application@2b61173
Missing comma is deprecated since 3.3.0: nette/forms@118561d
`Runtime` is no longer static: nette/forms@00de98d Keep compatibility with old version since 3.3 is too new.
Otherwise `composer dump-autoload -o` will warn when the temp directories contain generated containers:
Class Template_e24d735b58 located in ./examples/renderers/temp/cache/latte/examples-renderers-RenderersPresenter.latte--e24d735b58.php does not comply with psr-4 autoloading standard (rule: NextrasDemos\FormsRendering\Renderers\ => ./examples/renderers). Skipping.
Class Container_59e8c5ece8 located in ./examples/renderers/temp/cache/nette.configurator/Container_59e8c5ece8.php does not comply with psr-4 autoloading standard (rule: NextrasDemos\FormsRendering\Renderers\ => ./examples/renderers). Skipping.
Class Template_e535838971 located in ./examples/lattemacros/temp/cache/latte/examples-lattemacros-LatteMacrosPresenter.latte--e535838971.php does not comply with psr-4 autoloading standard (rule: NextrasDemos\FormsRendering\LatteMacros\ => ./examples/lattemacros). Skipping.
Class Container_c70388baf3 located in ./examples/lattemacros/temp/cache/nette.configurator/Container_c70388baf3.php does not comply with psr-4 autoloading standard (rule: NextrasDemos\FormsRendering\LatteMacros\ => ./examples/lattemacros). Skipping.
…ype()` `nette/forms` 3.1.0 renamed it to more sensible `getContainerPrototype()`: nette/forms@5378502 Let’s bump the minimal version since it is old enough: https://github.com/nette/forms/releases/tag/v3.1.0
`nette/bootstrap` 3.1.0 renamed `Nette\Configurator` to `Nette\Bootstrap\Configurator`: nette/bootstrap@8ff4ddb Also 3.2.0 deprecated `Configurator::enableDebugger()`: nette/bootstrap@70f9e96 `enableTracy()` is available since 3.0.0 nette/bootstrap@61f4ff5 Bumping since 3.1.0 is already pretty old: https://github.com/nette/bootstrap/releases/tag/v3.1.0
Collaborator
Author
|
All green now. |
Collaborator
Author
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.