Skip to content

Commit 18f8ce4

Browse files
committed
minor: More cleanups and type declarations for v2
1 parent 0d26a6b commit 18f8ce4

22 files changed

+64
-115
lines changed

composer.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"ext-dom": "*",
2222
"ext-libxml": "*",
2323
"php-webdriver/webdriver": "^1.8.2",
24-
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
25-
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
24+
"symfony/browser-kit": "^5.3 || ^6.0",
25+
"symfony/dependency-injection": "^5.3 || ^6.0",
2626
"symfony/deprecation-contracts": "^2.4 || ^3",
27-
"symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0",
28-
"symfony/http-client": "^4.4.11 || ^5.2 || ^6.0",
29-
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
30-
"symfony/process": "^4.4 || ^5.0 || ^6.0"
27+
"symfony/dom-crawler": "^5.3 || ^6.0",
28+
"symfony/http-client": "^5.3 || ^6.0",
29+
"symfony/http-kernel": "^5.3 || ^6.0",
30+
"symfony/process": "^5.3 || ^6.0"
3131
},
3232
"autoload": {
3333
"psr-4": { "Symfony\\Component\\Panther\\": "src/" }
@@ -44,9 +44,9 @@
4444
"sort-packages": true
4545
},
4646
"require-dev": {
47-
"symfony/css-selector": "^4.4 || ^5.0 || ^6.0",
48-
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
49-
"symfony/mime": "^4.4 || ^5.0 || ^6.0",
50-
"symfony/phpunit-bridge": "^5.2 || ^6.0"
47+
"symfony/css-selector": "^5.3 || ^6.0",
48+
"symfony/framework-bundle": "^5.3 || ^6.0",
49+
"symfony/mime": "^5.3 || ^6.0",
50+
"symfony/phpunit-bridge": "^5.3 || ^6.0"
5151
}
5252
}

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ parameters:
1616
# Require a redesign of the underlying Symfony components
1717
- '#Call to an undefined method DOMNode::getTagName\(\)\.#'
1818
- '#Return type \(void\) of method Symfony\\Component\\Panther\\DomCrawler\\Crawler::clear\(\) should be compatible with return type \(Facebook\\WebDriver\\WebDriverElement\) of method Facebook\\WebDriver\\WebDriverElement::clear\(\)#'
19-
- '#Method Symfony\\Component\\Panther\\DomCrawler\\Crawler::getIterator\(\) should return ArrayIterator<int, DOMNode> but returns ArrayIterator<\(int\|string\), Facebook\\WebDriver\\WebDriverElement>\.#'

src/Client.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@ final class Client extends AbstractBrowser implements WebDriver, JavaScriptExecu
5656
{
5757
use ExceptionThrower;
5858

59-
/**
60-
* @var WebDriver|null
61-
*/
62-
private $webDriver;
63-
private $browserManager;
64-
private $baseUri;
65-
private $isFirefox = false;
59+
private ?WebDriver $webDriver = null;
60+
private BrowserManagerInterface $browserManager;
61+
private ?string $baseUri = null;
62+
private bool $isFirefox = false;
6663

6764
/**
6865
* @param string[]|null $arguments

src/Cookie/CookieJar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final class CookieJar extends BaseCookieJar
2828
{
2929
use ExceptionThrower;
3030

31-
private $webDriver;
31+
private WebDriver $webDriver;
3232

3333
public function __construct(WebDriver $webDriver)
3434
{
@@ -146,7 +146,7 @@ private function getWebDriverCookie(string $name, string $path = '/', ?string $d
146146
}
147147

148148
$cookiePath = $cookie->getPath() ?? '/';
149-
if (0 !== strpos($path, $cookiePath)) {
149+
if (!str_starts_with($path, $cookiePath)) {
150150
return null;
151151
}
152152

src/DomCrawler/Crawler.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ final class Crawler extends BaseCrawler implements WebDriverElement
2828
{
2929
use ExceptionThrower;
3030

31-
private $elements;
32-
private $webDriver;
31+
private array $elements;
32+
private ?WebDriver $webDriver;
3333

3434
/**
3535
* @param WebDriverElement[] $elements
@@ -142,13 +142,6 @@ public function previousAll(): static
142142
return $this->createSubCrawlerFromXpath('preceding-sibling::*');
143143
}
144144

145-
public function parents(): self
146-
{
147-
trigger_deprecation('symfony/panther', '1.1', 'The %s() method is deprecated, use ancestors() instead.', __METHOD__);
148-
149-
return $this->ancestors();
150-
}
151-
152145
public function ancestors(): static
153146
{
154147
return $this->createSubCrawlerFromXpath('ancestor::*', true);

src/DomCrawler/Field/ChoiceFormField.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,8 @@ final class ChoiceFormField extends BaseChoiceFormField
2525
{
2626
use FormFieldTrait;
2727

28-
/**
29-
* @var string
30-
*/
31-
private $type;
32-
33-
/**
34-
* @var WebDriverSelectInterface
35-
*/
36-
private $selector;
28+
private string $type;
29+
private WebDriverSelectInterface $selector;
3730

3831
public function hasValue(): bool
3932
{

src/DomCrawler/Field/FileFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function setValue($value): void
6060
*
6161
* @param string $path The path to the file
6262
*/
63-
public function setFilePath($path): void
63+
public function setFilePath(string $path): void
6464
{
6565
$this->element->sendKeys($this->sanitizeValue($path));
6666
}

src/DomCrawler/Field/FormFieldTrait.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait FormFieldTrait
2626
{
2727
use ExceptionThrower;
2828

29-
private $element;
29+
private WebDriverElement $element;
3030

3131
public function __construct(WebDriverElement $element)
3232
{
@@ -54,15 +54,12 @@ public function isDisabled(): bool
5454
return null !== $this->element->getAttribute('disabled');
5555
}
5656

57-
private function setTextValue($value): void
57+
private function setTextValue(?string $value): void
5858
{
5959
// Ensure to clean field before sending keys.
6060
// Unable to use $this->element->clear(); because it triggers a change event on it's own which is unexpected behavior.
6161

6262
$v = $this->getValue();
63-
if (\is_array($v)) {
64-
throw new \InvalidArgumentException('The value must not be an array');
65-
}
6663

6764
$existingValueLength = \strlen($v);
6865
$deleteKeys = str_repeat(WebDriverKeys::BACKSPACE.WebDriverKeys::DELETE, $existingValueLength);

src/DomCrawler/Field/TextareaFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class TextareaFormField extends BaseTextareaFormField
2222
{
2323
use FormFieldTrait;
2424

25-
public function setValue($value): void
25+
public function setValue(?string $value): void
2626
{
2727
$this->setTextValue($value);
2828
}

src/DomCrawler/Form.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,9 @@ final class Form extends BaseForm
3737
{
3838
use ExceptionThrower;
3939

40-
/**
41-
* @var WebDriverElement
42-
*/
43-
private $button;
44-
45-
/**
46-
* @var WebDriverElement
47-
*/
48-
private $element;
49-
private $webDriver;
40+
private WebDriverElement $button;
41+
private WebDriverElement $element;
42+
private WebDriver $webDriver;
5043

5144
public function __construct(WebDriverElement $element, WebDriver $webDriver)
5245
{

0 commit comments

Comments
 (0)