Skip to content

Commit 3011210

Browse files
Fix PHP 8.4 deprecations and CS (#641)
1 parent 9f6010b commit 3011210

25 files changed

+69
-69
lines changed

src/Client.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,25 @@ final class Client extends AbstractBrowser implements WebDriver, JavaScriptExecu
6464
/**
6565
* @param string[]|null $arguments
6666
*/
67-
public static function createChromeClient(string $chromeDriverBinary = null, array $arguments = null, array $options = [], string $baseUri = null): self
67+
public static function createChromeClient(?string $chromeDriverBinary = null, ?array $arguments = null, array $options = [], ?string $baseUri = null): self
6868
{
6969
return new self(new ChromeManager($chromeDriverBinary, $arguments, $options), $baseUri);
7070
}
7171

7272
/**
7373
* @param string[]|null $arguments
7474
*/
75-
public static function createFirefoxClient(string $geckodriverBinary = null, array $arguments = null, array $options = [], string $baseUri = null): self
75+
public static function createFirefoxClient(?string $geckodriverBinary = null, ?array $arguments = null, array $options = [], ?string $baseUri = null): self
7676
{
7777
return new self(new FirefoxManager($geckodriverBinary, $arguments, $options), $baseUri);
7878
}
7979

80-
public static function createSeleniumClient(string $host = null, WebDriverCapabilities $capabilities = null, string $baseUri = null, array $options = []): self
80+
public static function createSeleniumClient(?string $host = null, ?WebDriverCapabilities $capabilities = null, ?string $baseUri = null, array $options = []): self
8181
{
8282
return new self(new SeleniumManager($host, $capabilities, $options), $baseUri);
8383
}
8484

85-
public function __construct(BrowserManagerInterface $browserManager, string $baseUri = null)
85+
public function __construct(BrowserManagerInterface $browserManager, ?string $baseUri = null)
8686
{
8787
$this->browserManager = $browserManager;
8888
$this->baseUri = $baseUri;
@@ -252,7 +252,7 @@ public function refreshCrawler(): PantherCrawler
252252
return $this->crawler = $this->createCrawler();
253253
}
254254

255-
public function request(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true): PantherCrawler
255+
public function request(string $method, string $uri, array $parameters = [], array $files = [], array $server = [], ?string $content = null, bool $changeHistory = true): PantherCrawler
256256
{
257257
if ('GET' !== $method) {
258258
throw new \InvalidArgumentException('Only the GET method is supported when using WebDriver.');
@@ -266,7 +266,7 @@ public function request(string $method, string $uri, array $parameters = [], arr
266266

267267
foreach (['parameters', 'files', 'server'] as $arg) {
268268
if ([] !== $$arg) {
269-
throw new \InvalidArgumentException(sprintf('The parameter "$%s" is not supported when using WebDriver.', $arg));
269+
throw new \InvalidArgumentException(\sprintf('The parameter "$%s" is not supported when using WebDriver.', $arg));
270270
}
271271
}
272272

@@ -773,9 +773,9 @@ public function ping(int $timeout = 1000): bool
773773
private function createException(string $implementableClass): \Exception
774774
{
775775
if (null === $this->webDriver) {
776-
return new \LogicException(sprintf('WebDriver not started yet. Call method `start()` first before calling any `%s` method.', $implementableClass));
776+
return new \LogicException(\sprintf('WebDriver not started yet. Call method `start()` first before calling any `%s` method.', $implementableClass));
777777
}
778778

779-
return new \RuntimeException(sprintf('"%s" does not implement "%s".', \get_class($this->webDriver), $implementableClass));
779+
return new \RuntimeException(\sprintf('"%s" does not implement "%s".', \get_class($this->webDriver), $implementableClass));
780780
}
781781
}

src/Cookie/CookieJar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function webDriverToSymfony(WebDriverCookie $cookie): Cookie
133133
return new Cookie($cookie->getName(), $cookie->getValue(), $expiry, $cookie->getPath(), (string) $cookie->getDomain(), (bool) $cookie->isSecure(), (bool) $cookie->isHttpOnly());
134134
}
135135

136-
private function getWebDriverCookie(string $name, string $path = '/', string $domain = null): ?WebDriverCookie
136+
private function getWebDriverCookie(string $name, string $path = '/', ?string $domain = null): ?WebDriverCookie
137137
{
138138
try {
139139
$cookie = $this->webDriver->manage()->getCookieNamed($name);

src/DomCrawler/Crawler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ final class Crawler extends BaseCrawler implements WebDriverElement
3434
/**
3535
* @param WebDriverElement[] $elements
3636
*/
37-
public function __construct(array $elements = [], WebDriver $webDriver = null, string $uri = null)
37+
public function __construct(array $elements = [], ?WebDriver $webDriver = null, ?string $uri = null)
3838
{
3939
$this->uri = $uri;
4040
$this->webDriver = $webDriver;
@@ -177,7 +177,7 @@ public function ancestors(): static
177177
/**
178178
* @see https://github.com/symfony/symfony/issues/26432
179179
*/
180-
public function children(string $selector = null): static
180+
public function children(?string $selector = null): static
181181
{
182182
$xpath = 'child::*';
183183
if (null !== $selector) {
@@ -203,7 +203,7 @@ public function nodeName(): string
203203
return $this->getElementOrThrow()->getTagName();
204204
}
205205

206-
public function text(string $default = null, bool $normalizeWhitespace = true): string
206+
public function text(?string $default = null, bool $normalizeWhitespace = true): string
207207
{
208208
if (!$normalizeWhitespace) {
209209
throw new \InvalidArgumentException('Panther only supports getting normalized text.');
@@ -220,7 +220,7 @@ public function text(string $default = null, bool $normalizeWhitespace = true):
220220
}
221221
}
222222

223-
public function html(string $default = null): string
223+
public function html(?string $default = null): string
224224
{
225225
try {
226226
$element = $this->getElementOrThrow();
@@ -274,19 +274,19 @@ public function filter($selector): static
274274
public function selectLink($value): static
275275
{
276276
return $this->selectFromXpath(
277-
sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %1$s)]]', self::xpathLiteral(' '.$value.' '))
277+
\sprintf('descendant-or-self::a[contains(concat(\' \', normalize-space(string(.)), \' \'), %1$s) or ./img[contains(concat(\' \', normalize-space(string(@alt)), \' \'), %1$s)]]', self::xpathLiteral(' '.$value.' '))
278278
);
279279
}
280280

281281
public function selectImage($value): static
282282
{
283-
return $this->selectFromXpath(sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', self::xpathLiteral($value)));
283+
return $this->selectFromXpath(\sprintf('descendant-or-self::img[contains(normalize-space(string(@alt)), %s)]', self::xpathLiteral($value)));
284284
}
285285

286286
public function selectButton($value): static
287287
{
288288
return $this->selectFromXpath(
289-
sprintf(
289+
\sprintf(
290290
'descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %2$s) or @id=%3$s or @name=%3$s]',
291291
'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")',
292292
self::xpathLiteral(' '.$value.' '),
@@ -330,7 +330,7 @@ public function images(): array
330330
return $images;
331331
}
332332

333-
public function form(array $values = null, $method = null): Form
333+
public function form(?array $values = null, $method = null): Form
334334
{
335335
$form = new Form($this->getElementOrThrow(), $this->webDriver);
336336
if (null !== $values) {
@@ -393,7 +393,7 @@ private function selectFromXpath(string $xpath): self
393393
/**
394394
* @param WebDriverElement[]|null $nodes
395395
*/
396-
private function createSubCrawler(array $nodes = null): self
396+
private function createSubCrawler(?array $nodes = null): self
397397
{
398398
return new self($nodes ?? [], $this->webDriver, $this->uri);
399399
}

src/DomCrawler/Field/ChoiceFormField.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function select($value): void
5252
public function tick(): void
5353
{
5454
if ('checkbox' !== $type = $this->element->getAttribute('type')) {
55-
throw new \LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type));
55+
throw new \LogicException(\sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type));
5656
}
5757

5858
$this->setValue(true);
@@ -66,7 +66,7 @@ public function tick(): void
6666
public function untick(): void
6767
{
6868
if ('checkbox' !== $type = $this->element->getAttribute('type')) {
69-
throw new \LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type));
69+
throw new \LogicException(\sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->element->getAttribute('name'), $type));
7070
}
7171

7272
$this->setValue(false);
@@ -114,7 +114,7 @@ public function setValue($value): void
114114
{
115115
if (\is_bool($value)) {
116116
if ('checkbox' !== $this->type) {
117-
throw new \InvalidArgumentException(sprintf('Invalid argument of type "%s"', \gettype($value)));
117+
throw new \InvalidArgumentException(\sprintf('Invalid argument of type "%s"', \gettype($value)));
118118
}
119119

120120
if ($value) {
@@ -189,12 +189,12 @@ protected function initialize(): void
189189
{
190190
$tagName = $this->element->getTagName();
191191
if ('input' !== $tagName && 'select' !== $tagName) {
192-
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $tagName));
192+
throw new \LogicException(\sprintf('A ChoiceFormField can only be created from an input or select tag (%s given).', $tagName));
193193
}
194194

195195
$type = strtolower((string) $this->element->getAttribute('type'));
196196
if ('input' === $tagName && 'checkbox' !== $type && 'radio' !== $type) {
197-
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $type));
197+
throw new \LogicException(\sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $type));
198198
}
199199

200200
$this->type = 'select' === $tagName ? 'select' : $type;

src/DomCrawler/Field/FileFormField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ protected function initialize(): void
6767
{
6868
$tagName = $this->element->getTagName();
6969
if ('input' !== $tagName) {
70-
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag (%s given).', $tagName));
70+
throw new \LogicException(\sprintf('A FileFormField can only be created from an input tag (%s given).', $tagName));
7171
}
7272

7373
$type = strtolower($this->element->getAttribute('type'));
7474
if ('file' !== $type) {
75-
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $type));
75+
throw new \LogicException(\sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $type));
7676
}
7777

7878
$value = $this->element->getAttribute('value');

src/DomCrawler/Field/InputFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function initialize(): void
4848
{
4949
$tagName = $this->element->getTagName();
5050
if ('input' !== $tagName && 'button' !== $tagName) {
51-
throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $tagName));
51+
throw new \LogicException(\sprintf('An InputFormField can only be created from an input or button tag (%s given).', $tagName));
5252
}
5353

5454
$type = strtolower((string) $this->element->getAttribute('type'));

src/DomCrawler/Field/TextareaFormField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function initialize(): void
3636
{
3737
$tagName = $this->element->getTagName();
3838
if ('textarea' !== $tagName) {
39-
throw new \LogicException(sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $tagName));
39+
throw new \LogicException(\sprintf('A TextareaFormField can only be created from a textarea tag (%s given).', $tagName));
4040
}
4141
}
4242
}

src/DomCrawler/Form.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private function setElement(WebDriverElement $element): void
6060
try {
6161
$form = $this->webDriver->findElement(WebDriverBy::id($formId));
6262
} catch (NoSuchElementException $e) {
63-
throw new \LogicException(sprintf('The selected node has an invalid form attribute (%s).', $formId));
63+
throw new \LogicException(\sprintf('The selected node has an invalid form attribute (%s).', $formId));
6464
}
6565

6666
$this->element = $form;
@@ -76,7 +76,7 @@ private function setElement(WebDriverElement $element): void
7676
}
7777
} while ('form' !== $element->getTagName());
7878
} elseif ('form' !== $tagName = $element->getTagName()) {
79-
throw new \LogicException(sprintf('Unable to submit on a "%s" tag.', $tagName));
79+
throw new \LogicException(\sprintf('Unable to submit on a "%s" tag.', $tagName));
8080
}
8181

8282
$this->element = $element;
@@ -166,7 +166,7 @@ public function getFiles(): array
166166
continue;
167167
}
168168

169-
if ($field instanceof Field\FileFormField) {
169+
if ($field instanceof FileFormField) {
170170
$files[$field->getName()] = $field->getValue();
171171
}
172172
}
@@ -270,7 +270,7 @@ protected function getRawUri(): string
270270
private function getFormElement(string $name): WebDriverElement
271271
{
272272
return $this->element->findElement(WebDriverBy::xpath(
273-
sprintf('.//input[@name=%1$s] | .//textarea[@name=%1$s] | .//select[@name=%1$s] | .//button[@name=%1$s] | .//input[@name=%2$s] | .//textarea[@name=%2$s] | .//select[@name=%2$s] | .//button[@name=%2$s]', XPathEscaper::escapeQuotes($name), XPathEscaper::escapeQuotes($name.'[]'))
273+
\sprintf('.//input[@name=%1$s] | .//textarea[@name=%1$s] | .//select[@name=%1$s] | .//button[@name=%1$s] | .//input[@name=%2$s] | .//textarea[@name=%2$s] | .//select[@name=%2$s] | .//button[@name=%2$s]', XPathEscaper::escapeQuotes($name), XPathEscaper::escapeQuotes($name.'[]'))
274274
));
275275
}
276276

src/DomCrawler/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class Image extends BaseImage
2929
public function __construct(WebDriverElement $element)
3030
{
3131
if ('img' !== $tagName = $element->getTagName()) {
32-
throw new \LogicException(sprintf('Unable to visualize a "%s" tag.', $tagName));
32+
throw new \LogicException(\sprintf('Unable to visualize a "%s" tag.', $tagName));
3333
}
3434

3535
$this->element = $element;

src/DomCrawler/Link.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function __construct(WebDriverElement $element, string $currentUri)
3030
{
3131
$tagName = $element->getTagName();
3232
if ('a' !== $tagName && 'area' !== $tagName && 'link' !== $tagName) {
33-
throw new \LogicException(sprintf('Unable to navigate from a "%s" tag.', $tagName));
33+
throw new \LogicException(\sprintf('Unable to navigate from a "%s" tag.', $tagName));
3434
}
3535

3636
$this->element = $element;

0 commit comments

Comments
 (0)