From 7dc33791906dfc25d02e6fe774296bd5ba455fad Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 11 Jan 2025 12:22:53 +0100 Subject: [PATCH 1/3] PHPStan: Fix getForm() result type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nette/forms 3.1.15 clarified that the `Container::getForm` method can only return `null` when passed `throw: false`: https://github.com/nette/forms/commit/ee43bfc6e86b0c1f7e56655ac5571b4102392f9a With PHPStan 2.0 this would be noticed and result in an error: 384 Strict comparison using !== between Nette\Forms\Form and null will always evaluate to true. 🪪 notIdentical.alwaysTrue Let’s use non-throwing variant and also add the PHPDoc to be explicit. --- src/Multiplier.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Multiplier.php b/src/Multiplier.php index 8cf4c12..2fe7c42 100644 --- a/src/Multiplier.php +++ b/src/Multiplier.php @@ -110,6 +110,9 @@ public static function register(string $name = 'addMultiplier'): void }); } + /** + * @return ($throw is true ? Form : ?Form) + */ public function getForm(bool $throw = true): ?Form { if ($this->form) { @@ -378,7 +381,7 @@ protected function isValidMaxCopies(): bool protected function isFormSubmitted(): bool { - return $this->getForm() !== null && $this->getForm()->isAnchored() && $this->getForm()->isSubmitted(); + return $this->getForm(false) !== null && $this->getForm()->isAnchored() && $this->getForm()->isSubmitted(); } protected function loadHttpData(): void From 07a1009a4897039db9369badf5c28e228a0c0a60 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 11 Jan 2025 11:54:12 +0100 Subject: [PATCH 2/3] Bump PHPStan to 2.0 https://github.com/contributte/phpstan/releases/tag/v0.2.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b533ae7..732957e 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "nette/di": "^3.1.0", "latte/latte": "^3.0.0", "contributte/qa": "^0.3", - "contributte/phpstan": "^0.1", + "contributte/phpstan": "^0.2", "webchemistry/testing-helpers": "^4.0.0" }, "conflict": { From 95335308e14b6be64341bc7dffee0c705753e01e Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 18 Jan 2025 00:03:52 +0100 Subject: [PATCH 3/3] phpstan: Ignore Container::getComponents() returning incorrect type This is a phpstan-nette bug. --- phpstan.neon | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index 2cc7d7c..5eda96f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,3 +16,11 @@ parameters: paths: - src - .docs + + ignoreErrors: + # https://github.com/phpstan/phpstan-nette/issues/141 + - + message: '#^Parameter \#1 \$array of function array_filter expects array, Iterator\ given\.$#' + identifier: argument.type + count: 3 + path: src/Multiplier.php