Skip to content

Fix ci, deprecations, forms 3.3 support#21

Merged
hrach merged 17 commits into
nextras:masterfrom
jtojnar:duck-fix
Jul 14, 2026
Merged

Fix ci, deprecations, forms 3.3 support#21
hrach merged 17 commits into
nextras:masterfrom
jtojnar:duck-fix

Conversation

@jtojnar

@jtojnar jtojnar commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator
  • phpstan: Ignore temp files
  • LatteTags: Fix PHPStan error with nette/forms < 3.3

@hrach

hrach commented Jul 14, 2026

Copy link
Copy Markdown
Member

I'm totally ok with dropping PHP 8.0.

jtojnar added 10 commits July 14, 2026 11:58
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
@jtojnar jtojnar changed the title LatteTags: Fix PHPStan error with nette/forms < 3.3 Fix ci, deprecations, support Jul 14, 2026
@jtojnar jtojnar changed the title Fix ci, deprecations, support Fix ci, deprecations, forms 3.3 support Jul 14, 2026
jtojnar added 6 commits July 14, 2026 13:01
`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
@jtojnar

jtojnar commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

All green now.

@hrach hrach merged commit 0994ede into nextras:master Jul 14, 2026
5 checks passed
@jtojnar jtojnar deleted the duck-fix branch July 14, 2026 15:21
@jtojnar

jtojnar commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator Author

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