Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH PHP 8.1 compatibility #18

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 15 additions & 15 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, $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($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 @@ -528,7 +528,7 @@ public function setCookie($name, $value = null)

$cookieArray = array(
'name' => $name,
'value' => urlencode($value),
'value' => urlencode($value ?? ''),
'secure' => false, // thanks, chibimagic!
);

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($element->getTagName() ?? '');
$elementType = strtolower($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($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($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($element->getTagName() ?? '');

if ('input' === $tagName && 'radio' === strtolower($element->getAttribute('type'))) {
if ('input' === $tagName && 'radio' === strtolower($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\(]/', $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($script ?? ''), 'return ')) {
$script = "return {$script};";
}

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