From 005c5f37802ae0887326139b4897f7ecb2a87a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mor=C3=A1vek?= Date: Fri, 9 Feb 2024 07:03:47 +0100 Subject: [PATCH] Strict hidden input value type handling --- src/FileUploadControl/FileUploadControl.php | 5 +++-- tests/PHPStan/conditional.config.php | 5 ----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/FileUploadControl/FileUploadControl.php b/src/FileUploadControl/FileUploadControl.php index 04eee36..eef109e 100644 --- a/src/FileUploadControl/FileUploadControl.php +++ b/src/FileUploadControl/FileUploadControl.php @@ -426,8 +426,9 @@ protected function getThumbnailProvider(): ThumbnailProvider protected function getUploadNamespace(): UploadNamespace { - $nameSpaceValue = (string) $this->getNamespaceControl()->getValue(); - if (UploadNamespace::isValid($nameSpaceValue)) { + /** @var string|null $nameSpaceValue */ + $nameSpaceValue = $this->getNamespaceControl()->getValue(); + if ($nameSpaceValue !== null && UploadNamespace::isValid($nameSpaceValue)) { return UploadNamespace::fromString($nameSpaceValue); } diff --git a/tests/PHPStan/conditional.config.php b/tests/PHPStan/conditional.config.php index f475ad5..1e3127a 100644 --- a/tests/PHPStan/conditional.config.php +++ b/tests/PHPStan/conditional.config.php @@ -24,11 +24,6 @@ } if (InstalledVersions::satisfies(new VersionParser(), 'nette/forms', '<3.2')) { - $config['parameters']['ignoreErrors'][] = [ - 'message' => '#^Cannot cast mixed to string\\.$#', - 'path' => '../../src/FileUploadControl/FileUploadControl.php', - 'count' => 1, - ]; $config['parameters']['ignoreErrors'][] = [ 'message' => '#^Return type \\(string\\|Stringable\\|null\\) of method Nepada\\\\FileUploadControl\\\\Validation\\\\FakeUploadControl\\:\\:getCaption\\(\\) should be covariant with return type \\(object\\|string\\) of method Nette\\\\Forms\\\\Controls\\\\BaseControl\\:\\:getCaption\\(\\)$#', 'path' => '../../src/FileUploadControl/Validation/FakeUploadControl.php',