From 7715b024cebaea9eec3a206cae91721c8425ddc1 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 5 Apr 2022 10:44:41 +1200 Subject: [PATCH] ENH PHP 8.1 compatibility --- src/FacebookFactory.php | 2 +- src/FacebookWebDriver.php | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/FacebookFactory.php b/src/FacebookFactory.php index 73324b3f..90f07c4d 100644 --- a/src/FacebookFactory.php +++ b/src/FacebookFactory.php @@ -44,7 +44,7 @@ public function buildDriver(array $config) ['w3c' => false] ); - $capabilities = array_replace($this->guessCapabilities(), $extraCapabilities, $config['capabilities']); + $capabilities = array_replace($this->guessCapabilities() ?: [], $extraCapabilities, $config['capabilities']); // Build driver definition return new Definition(FacebookWebDriver::class, [ diff --git a/src/FacebookWebDriver.php b/src/FacebookWebDriver.php index 1997fa58..aaf4e01e 100755 --- a/src/FacebookWebDriver.php +++ b/src/FacebookWebDriver.php @@ -124,7 +124,7 @@ protected function initCapabilities($desiredCapabilities = []) { // Build base capabilities $browserName = $this->getBrowserName(); - if ($browserName && method_exists(DesiredCapabilities::class, $browserName)) { + if ($browserName && method_exists(DesiredCapabilities::class, (string) $browserName)) { /** @var DesiredCapabilities $caps */ $caps = DesiredCapabilities::$browserName(); } else { @@ -307,7 +307,7 @@ protected function withSyn() */ protected static function charToOptions($char, $modifier = null) { - $ord = ord($char); + $ord = ord((string) $char); if (is_numeric($char)) { $ord = $char; } @@ -355,7 +355,7 @@ protected function executeJsOnXpath($xpath, $script, $sync = true) */ private function executeJsOnElement(RemoteWebElement $element, $script, $sync = true) { - $script = str_replace('{{ELEMENT}}', 'arguments[0]', $script); + $script = str_replace('{{ELEMENT}}', 'arguments[0]', $script ?: ''); if ($sync) { return $this->webDriver->executeScript($script, [$element]); } @@ -606,7 +606,7 @@ public function getText($xpath) { $node = $this->findElement($xpath); $text = $node->getText(); - $text = (string) str_replace(array("\r", "\r\n", "\n"), ' ', $text); + $text = (string) str_replace(array("\r", "\r\n", "\n"), ' ', $text ?: ''); return $text; } @@ -643,8 +643,8 @@ public function getAttribute($xpath, $name) public function getValue($xpath) { $element = $this->findElement($xpath); - $elementName = strtolower($element->getTagName()); - $elementType = strtolower($element->getAttribute('type')); + $elementName = strtolower((string) $element->getTagName()); + $elementType = strtolower((string) $element->getAttribute('type')); // Getting the value of a checkbox returns its value if selected. if ('input' === $elementName && 'checkbox' === $elementType) { @@ -712,7 +712,7 @@ public function getValue($xpath) public function setValue($xpath, $value) { $element = $this->findElement($xpath); - $elementName = strtolower($element->getTagName()); + $elementName = strtolower((string) $element->getTagName()); if ('select' === $elementName) { if (is_array($value)) { @@ -731,7 +731,7 @@ public function setValue($xpath, $value) } if ('input' === $elementName) { - $elementType = strtolower($element->getAttribute('type')); + $elementType = strtolower((string) $element->getAttribute('type')); if (in_array($elementType, array('submit', 'image', 'button', 'reset'))) { throw new DriverException(sprintf('Impossible to set value an element with XPath "%s" as it is not a select, textarea or textbox', $xpath)); @@ -814,9 +814,9 @@ public function isChecked($xpath) public function selectOption($xpath, $value, $multiple = false) { $element = $this->findElement($xpath); - $tagName = strtolower($element->getTagName()); + $tagName = strtolower((string) $element->getTagName()); - if ('input' === $tagName && 'radio' === strtolower($element->getAttribute('type'))) { + if ('input' === $tagName && 'radio' === strtolower((string) $element->getAttribute('type'))) { $this->selectRadioValue($element, $value); return; @@ -1013,8 +1013,8 @@ public function dragBy($sourceXpath, $xOffset, $yOffset) */ public function executeScript($script) { - if (preg_match('/^function[\s\(]/', $script)) { - $script = preg_replace('/;$/', '', $script); + if (preg_match('/^function[\s\(]/', (string) $script)) { + $script = preg_replace('/;$/', '', $script ?: ''); $script = '(' . $script . ')'; } @@ -1026,7 +1026,7 @@ public function executeScript($script) */ public function evaluateScript($script) { - if (0 !== strpos(trim($script), 'return ')) { + if (0 !== strpos(trim((string) $script), 'return ')) { $script = "return {$script};"; } @@ -1144,7 +1144,7 @@ private function selectRadioValue(RemoteWebElement $element, $value) XPATH; $xpath = sprintf( - $xpath, + (string) $xpath, $this->xpathEscaper->escapeLiteral($formId), $this->xpathEscaper->escapeLiteral($name), $this->xpathEscaper->escapeLiteral($value)