From 3702de243789527234233bab1e0549b83d9f2013 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 13 Apr 2022 17:41:57 +1200 Subject: [PATCH] ENH PHP 8.1 compatibility --- src/FacebookFactory.php | 2 +- src/FacebookWebDriver.php | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/FacebookFactory.php b/src/FacebookFactory.php index 73324b3f..d44c719d 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..12c5dca3 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, $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($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]); } @@ -528,7 +528,7 @@ public function setCookie($name, $value = null) $cookieArray = array( 'name' => $name, - 'value' => urlencode($value), + 'value' => urlencode($value ?? ''), 'secure' => false, // thanks, chibimagic! ); @@ -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($element->getTagName() ?? ''); + $elementType = strtolower($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($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($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($element->getTagName() ?? ''); - if ('input' === $tagName && 'radio' === strtolower($element->getAttribute('type'))) { + if ('input' === $tagName && 'radio' === strtolower($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\(]/', $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($script ?? ''), 'return ')) { $script = "return {$script};"; } @@ -1144,7 +1144,7 @@ private function selectRadioValue(RemoteWebElement $element, $value) XPATH; $xpath = sprintf( - $xpath, + $xpath ?? '', $this->xpathEscaper->escapeLiteral($formId), $this->xpathEscaper->escapeLiteral($name), $this->xpathEscaper->escapeLiteral($value)