Skip to content

Commit

Permalink
ENH PHP 8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Apr 4, 2022
1 parent 1c956e7 commit 7715b02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/FacebookFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down
28 changes: 14 additions & 14 deletions src/FacebookWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 . ')';
}

Expand All @@ -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};";
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7715b02

Please sign in to comment.