From 05ffb4ec373affb2830d66a51f3d2bbec2ef4f64 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 22 Nov 2025 11:14:50 +0100 Subject: [PATCH] Improve the phpstan setup - add more precise types for some array parameters - ignore missing iterable value errors only for the selector and locator arguments related to our SelectorInterface rather than disabling the check globally --- composer.json | 2 +- phpstan.dist.neon | 7 ++++++- src/Driver/CoreDriver.php | 4 ++++ src/Driver/DriverInterface.php | 4 ++++ src/Element/NodeElement.php | 4 ++++ src/Element/TraversableElement.php | 2 ++ tests/SessionTest.php | 2 ++ 7 files changed, 23 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index be78cf12e..56c70578f 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require-dev": { - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^1.12.32", "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^8.5.22 || ^9.5.11", "symfony/error-handler": "^4.4 || ^5.0 || ^6.0 || ^7.0", diff --git a/phpstan.dist.neon b/phpstan.dist.neon index ee759c720..15cdbabde 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -3,13 +3,18 @@ parameters: paths: - src - tests - checkMissingIterableValueType: false checkMissingCallableSignature: true treatPhpDocTypesAsCertain: false ignoreErrors: - '#^Method Behat\\Mink\\Tests\\[^:]+Test(Case)?\:\:test\w*\(\) has no return type specified\.$#' - '#^Method Behat\\Mink\\Tests\\[^:]+Test(Case)?\:\:provide\w*\(\) has no return type specified\.$#' - '#^Method Behat\\Mink\\Tests\\[^:]+Test(Case)?\:\:get\w*\(\) has no return type specified\.$#' + - + message: '#^Method Behat\\Mink\\[^:]+\:\:\w+\(\) has parameter \$selector with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + - + message: '#^Method Behat\\Mink\\[^:]+\:\:\w+\(\) has parameter \$locator with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue includes: - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/src/Driver/CoreDriver.php b/src/Driver/CoreDriver.php index a5940ff91..9c3ef242b 100644 --- a/src/Driver/CoreDriver.php +++ b/src/Driver/CoreDriver.php @@ -388,6 +388,8 @@ public function getAttribute(string $xpath, string $name) * * @return string|bool|array|null * + * @phpstan-return string|bool|list|null + * * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done */ @@ -400,6 +402,8 @@ public function getValue(string $xpath) * @param string $xpath * @param string|bool|array $value * + * @phpstan-param string|bool|list $value + * * @return void * * @throws UnsupportedDriverActionException When operation not supported by the driver diff --git a/src/Driver/DriverInterface.php b/src/Driver/DriverInterface.php index b36cc778b..9c40b4493 100644 --- a/src/Driver/DriverInterface.php +++ b/src/Driver/DriverInterface.php @@ -396,6 +396,8 @@ public function getAttribute( * * @return string|bool|array|null * + * @phpstan-return string|bool|list|null + * * @throws UnsupportedDriverActionException When operation not supported by the driver * @throws DriverException When the operation cannot be done */ @@ -412,6 +414,8 @@ public function getValue( * @param string $xpath * @param string|bool|array $value * + * @phpstan-param string|bool|list $value + * * @return void * * @throws UnsupportedDriverActionException When operation not supported by the driver diff --git a/src/Element/NodeElement.php b/src/Element/NodeElement.php index 155ac77d4..65d98c3cd 100644 --- a/src/Element/NodeElement.php +++ b/src/Element/NodeElement.php @@ -96,6 +96,8 @@ public function getTagName() * Calling this method on other elements than form fields or option elements is not allowed. * * @return string|bool|array|null + * + * @phpstan-return string|bool|list|null */ public function getValue() { @@ -109,6 +111,8 @@ public function getValue() * * @param string|bool|array $value * + * @phpstan-param string|bool|list $value + * * @return void * * @see NodeElement::getValue for the format of the value for each type of field diff --git a/src/Element/TraversableElement.php b/src/Element/TraversableElement.php index 238da5168..392f146c5 100644 --- a/src/Element/TraversableElement.php +++ b/src/Element/TraversableElement.php @@ -149,6 +149,8 @@ public function findField(string $locator) * @param string $locator input id, name or label * @param string|bool|array $value value * + * @phpstan-param string|bool|list $value + * * @return void * * @throws ElementNotFoundException diff --git a/tests/SessionTest.php b/tests/SessionTest.php index e1ecc4665..0efe58bf0 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -175,6 +175,8 @@ public function testGetResponseHeaders() } /** + * @param array> $headers + * * @dataProvider provideResponseHeader */ public function testGetResponseHeader(?string $expected, string $name, array $headers)