Skip to content

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Jun 8, 2025

When trying this with latest Nette, I got several crashes. Trying to fix them all and increase PHPStan level so that I can be more certain more are not hiding in the shadows.

@jtojnar jtojnar changed the title Fix Call to undefined method WeakMap::contains() Fix crashes with Nette 3.2 Jun 8, 2025
jtojnar added 9 commits June 8, 2025 14:03
Nette Forms 3.2.0 replaced SplObjectStorage with WeakMap
nette/forms@ec8ecfd
291a615 introduced type hints so the method now expects a string for name, consistent with `nette/component-model` (nette/component-model@47dab8f).

This unfortunately leads to an error when rendering a form since range produces integers:

    Kdyby\Replicator\Container::createOne(): Argument Kdyby#1 ($name) must be of type ?string, int given
`Container::getComponents()` returns array when `$deep` is false (by default):
nette/component-model@7f613ee

The method also no longer takes any arguments:
nette/component-model@4e0946a
It was introduced in 7ae4bd3 as using `string|false` but the actual type was not reflected in the annotation.

Let’s tighten it up as `?string` and use type hint.

This is required for PHPStan level 3.
The check was there to allow passing the callable as the first and only argument but that got broken by introduction of type hints in 291a615 so PHPStan would complain:

    Call to function is_bool() with bool will always evaluate to true.

But we do not need this now that we support PHP 8 with named arguments:
https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments
jtojnar added 3 commits June 8, 2025 14:12
Mostly adding generic types to iterables.

Disabling `treatPhpDocTypesAsCertain` since we cannot guarantee the caller of public methods will respect the annotation and without this, PHPStan will complain about redundant `is_iterable`.
This was a bit annoying since the annotations in nette and phpstan-nette are not the most precise.
@jtojnar jtojnar force-pushed the fixes branch 3 times, most recently from e7cc49e to 5a15cae Compare June 8, 2025 12:54
@solcik
Copy link
Contributor

solcik commented Jun 8, 2025

@jakubboucek can I ask you for a review?

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