Skip to content

Commit 0d75b54

Browse files
authored
Fix various phpstan warnings (#57)
1 parent 00b5f88 commit 0d75b54

File tree

5 files changed

+62
-16
lines changed

5 files changed

+62
-16
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ indent_size = 2
1414

1515
[*.php]
1616
ij_php_align_multiline_parameters = false
17+
18+
[*.neon]
19+
indent_style = tab

phpstan.dist.neon

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
parameters:
2-
level: 8
3-
paths:
4-
- src
5-
- tests
6-
checkMissingIterableValueType: false
7-
treatPhpDocTypesAsCertain: false
8-
91
includes:
10-
- vendor/phpstan/phpstan-phpunit/extension.neon
11-
- vendor/phpstan/phpstan-phpunit/rules.neon
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
3+
- vendor/phpstan/phpstan-phpunit/rules.neon
4+
5+
parameters:
6+
level: 8
7+
paths:
8+
- src
9+
- tests
10+
ignoreErrors:
11+
-
12+
# See: https://github.com/php-webdriver/php-webdriver/pull/1120
13+
message: '#^Parameter \#1 \$seconds of method Facebook\\WebDriver\\WebDriverTimeouts\:\:implicitlyWait\(\) expects int, float\|int given\.$#'
14+
identifier: argument.type
15+
count: 1
16+
path: src/WebdriverClassicDriver.php
17+
-
18+
# See: https://github.com/php-webdriver/php-webdriver/pull/1120
19+
message: '#^Parameter \#1 \$seconds of method Facebook\\WebDriver\\WebDriverTimeouts\:\:pageLoadTimeout\(\) expects int, float\|int given\.$#'
20+
identifier: argument.type
21+
count: 1
22+
path: src/WebdriverClassicDriver.php
23+
-
24+
# See: https://github.com/php-webdriver/php-webdriver/pull/1120
25+
message: '#^Parameter \#1 \$seconds of method Facebook\\WebDriver\\WebDriverTimeouts\:\:setScriptTimeout\(\) expects int, float\|int given\.$#'
26+
identifier: argument.type
27+
count: 1
28+
path: src/WebdriverClassicDriver.php

src/WebdriverClassicDriver.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
use JetBrains\PhpStorm\Language;
3333

3434
/**
35+
* @phpstan-type TTimeouts array{script?: null|numeric, implicit?: null|numeric, page?: null|numeric, "page load"?: null|numeric, pageLoad?: null|numeric}
36+
* @phpstan-type TCapabilities array<string, mixed>
37+
* @phpstan-type TElementValue array<array-key, mixed>|bool|mixed|string|null
3538
* @phpstan-type TWebDriverInstantiator callable(string $driverHost, DesiredCapabilities $capabilities): RemoteWebDriver
3639
*/
3740
class WebdriverClassicDriver extends CoreDriver
@@ -80,6 +83,9 @@ class WebdriverClassicDriver extends CoreDriver
8083

8184
private DesiredCapabilities $desiredCapabilities;
8285

86+
/**
87+
* @var TTimeouts
88+
*/
8389
private array $timeouts = [];
8490

8591
private string $webDriverHost;
@@ -93,6 +99,7 @@ class WebdriverClassicDriver extends CoreDriver
9399

94100
/**
95101
* @param string $browserName One of 'edge', 'firefox', 'chrome' or any one of {@see WebDriverBrowserType} constants.
102+
* @param TCapabilities $desiredCapabilities
96103
* @param TWebDriverInstantiator|null $webDriverInstantiator
97104
*/
98105
public function __construct(
@@ -340,12 +347,16 @@ public function getAttribute(
340347
return $this->executeJsOnXpath($xpath, $script);
341348
}
342349

350+
/**
351+
* {@inheritdoc}
352+
* @return TElementValue
353+
*/
343354
public function getValue(
344355
#[Language('XPath')]
345356
string $xpath
346357
) {
347358
$element = $this->findElement($xpath);
348-
$widgetType = strtolower($element->getTagName() ?? '');
359+
$widgetType = $element->getTagName();
349360
if ($widgetType === 'input') {
350361
$widgetType = strtolower((string)$element->getAttribute('type'));
351362
}
@@ -380,13 +391,17 @@ public function getValue(
380391
}
381392
}
382393

394+
/**
395+
* {@inheritdoc}
396+
* @param TElementValue $value
397+
*/
383398
public function setValue(
384399
#[Language('XPath')]
385400
string $xpath,
386401
$value
387402
): void {
388403
$element = $this->findElement($xpath);
389-
$widgetType = strtolower($element->getTagName() ?? '');
404+
$widgetType = $element->getTagName();
390405
if ($widgetType === 'input') {
391406
$widgetType = strtolower((string)$element->getAttribute('type'));
392407
}
@@ -519,7 +534,7 @@ public function selectOption(
519534
bool $multiple = false
520535
): void {
521536
$element = $this->findElement($xpath);
522-
$tagName = strtolower($element->getTagName() ?? '');
537+
$tagName = $element->getTagName();
523538

524539
if ($tagName === 'input' && strtolower((string)$element->getAttribute('type')) === 'radio') {
525540
$this->selectRadioValue($element, $value);
@@ -747,7 +762,7 @@ public function getWebDriverSessionId(): ?string
747762
/**
748763
* Sets the timeouts to apply to the webdriver session
749764
*
750-
* @param array $timeouts The session timeout settings: Array of {script, implicit, page} => time in milliseconds
765+
* @param TTimeouts $timeouts The session timeout settings: Array of {script, implicit, page} => time in milliseconds
751766
* @throws DriverException
752767
* @api
753768
*/
@@ -805,6 +820,8 @@ private function getNormalisedBrowserName(): string
805820
/**
806821
* Detect and assign appropriate browser capabilities
807822
*
823+
* @param TCapabilities $desiredCapabilities
824+
*
808825
* @see https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities
809826
*/
810827
private function initCapabilities(array $desiredCapabilities): DesiredCapabilities

tests/Custom/CapabilityTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
use Mink\WebdriverClassicDriver\Tests\WebDriverMockingTrait;
66
use Mink\WebdriverClassicDriver\WebdriverClassicDriver;
77

8+
/**
9+
* @phpstan-import-type TCapabilities from WebdriverClassicDriver
10+
*/
811
class CapabilityTest extends \PHPUnit\Framework\TestCase
912
{
1013
use WebDriverMockingTrait;
1114

1215
/**
13-
* @param array<string, mixed> $desiredCapabilities
14-
* @param array<string, mixed> $expectedCapabilities
16+
* @param TCapabilities $desiredCapabilities
17+
* @param TCapabilities $expectedCapabilities
1518
*
1619
* @dataProvider capabilitiesDataProvider
1720
*/
@@ -35,6 +38,9 @@ function ($host, $capabilities) use (&$actualCapabilities, $mockWebDriver) {
3538
$this->assertSame($expectedCapabilities, $actualCapabilities);
3639
}
3740

41+
/**
42+
* @return iterable<string, array{browserName: string, desiredCapabilities: TCapabilities, expectedCapabilities: TCapabilities}>
43+
*/
3844
public static function capabilitiesDataProvider(): iterable
3945
{
4046
yield 'unknown browser starts with default driver capabilities' => [

tests/Custom/TimeoutTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public function testDeprecatedShortPageLoadTimeoutThrowsException(string $type):
6565
$this->driver->visit($this->pathTo('/page_load.php?sleep=2'));
6666
}
6767

68+
/**
69+
* @return iterable<string, array{type: string}>
70+
*/
6871
public static function deprecatedPageLoadDataProvider(): iterable
6972
{
7073
yield 'selenium 3 style' => ['type' => 'pageLoad'];

0 commit comments

Comments
 (0)