Skip to content

Commit

Permalink
Fix spacings
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfausk committed Oct 8, 2020
1 parent 644d9a8 commit 7cbc07a
Showing 1 changed file with 60 additions and 47 deletions.
107 changes: 60 additions & 47 deletions src/PantherDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function getClient()
if (!$this->isStarted()) {
throw new DriverException('Client is not (yet) started.');
}

return $this->client;
}

Expand All @@ -85,7 +86,7 @@ public function setRemoveHostFromUrl($remove = true)
'setRemoveHostFromUrl() is deprecated as of 1.2 and will be removed in 2.0. Pass the base url in the constructor instead.',
E_USER_DEPRECATED
);
$this->removeHostFromUrl = (bool)$remove;
$this->removeHostFromUrl = (bool) $remove;
}

/**
Expand All @@ -101,7 +102,7 @@ public function setRemoveScriptFromUrl($remove = true)
'setRemoveScriptFromUrl() is deprecated as of 1.2 and will be removed in 2.0. Pass the base url in the constructor instead.',
E_USER_DEPRECATED
);
$this->removeScriptFromUrl = (bool)$remove;
$this->removeScriptFromUrl = (bool) $remove;
}

/**
Expand Down Expand Up @@ -252,42 +253,7 @@ public function setCookie($name, $value = null)

$jar = $this->getClient()->getCookieJar();
// @see: https://github.com/w3c/webdriver/issues/1238
$jar->set(new Cookie($name, \rawurlencode((string)$value)));
}

/**
* Deletes a cookie by name.
*
* @param string $name Cookie name.
*/
private function deleteCookie($name)
{
$path = $this->getCookiePath();
$jar = $this->getClient()->getCookieJar();

do {
if (null !== $jar->get($name, $path)) {
$jar->expire($name, $path);
}

$path = preg_replace('/.$/', '', $path);
} while ($path);
}

/**
* Returns current cookie path.
*
* @return string
*/
private function getCookiePath()
{
$path = dirname(parse_url($this->getCurrentUrl(), PHP_URL_PATH));

if ('\\' === DIRECTORY_SEPARATOR) {
$path = str_replace('\\', '/', $path);
}

return $path;
$jar->set(new Cookie($name, \rawurlencode((string) $value)));
}

/**
Expand Down Expand Up @@ -450,7 +416,7 @@ public function findElementXpaths($xpath)
{
$nodes = $this->getCrawler()->filterXPath($xpath);

$elements = array();
$elements = [];
foreach ($nodes as $i => $node) {
$elements[] = sprintf('(%s)[%d]', $xpath, $i + 1);
}
Expand Down Expand Up @@ -535,7 +501,7 @@ public function getValue($xpath)
$value = $element->getAttribute('value');
}

return $value;
return $value;
}

/**
Expand Down Expand Up @@ -595,7 +561,10 @@ public function selectOption($xpath, $value, $multiple = false)

if (!$field instanceof ChoiceFormField) {
throw new DriverException(
sprintf('Impossible to select an option on the element with XPath "%s" as it is not a select or radio input', $xpath)
sprintf(
'Impossible to select an option on the element with XPath "%s" as it is not a select or radio input',
$xpath
)
);
}

Expand Down Expand Up @@ -669,7 +638,7 @@ public function executeScript($script)
{
if (\preg_match('/^function[\s\(]/', $script)) {
$script = \preg_replace('/;$/', '', $script);
$script = '(' . $script . ')';
$script = '('.$script.')';
}

return $this->getClient()->executeScript($script);
Expand All @@ -681,7 +650,7 @@ public function executeScript($script)
public function evaluateScript($script)
{
if (0 !== \strpos(\trim($script), 'return ')) {
$script = 'return ' . $script;
$script = 'return '.$script;
}

return $this->getClient()->executeScript($script);
Expand Down Expand Up @@ -765,6 +734,41 @@ protected function prepareUrl($url)
return preg_replace('#(https?\://[^/]+)(/[^/\.]+\.php)?#', $replacement, $url);
}

/**
* Deletes a cookie by name.
*
* @param string $name Cookie name.
*/
private function deleteCookie($name)
{
$path = $this->getCookiePath();
$jar = $this->getClient()->getCookieJar();

do {
if (null !== $jar->get($name, $path)) {
$jar->expire($name, $path);
}

$path = preg_replace('/.$/', '', $path);
} while ($path);
}

/**
* Returns current cookie path.
*
* @return string
*/
private function getCookiePath()
{
$path = dirname(parse_url($this->getCurrentUrl(), PHP_URL_PATH));

if ('\\' === DIRECTORY_SEPARATOR) {
$path = str_replace('\\', '/', $path);
}

return $path;
}

/**
* Returns form field from XPath query.
*
Expand Down Expand Up @@ -844,7 +848,9 @@ private function getInputFormField($xpath)
try {
$inputFormField = new InputFormField($element);
} catch (\LogicException $e) {
throw new DriverException(sprintf('Impossible to check the element with XPath "%s" as it is not an input form field.', $xpath));
throw new DriverException(
sprintf('Impossible to check the element with XPath "%s" as it is not an input form field.', $xpath)
);
}

return $inputFormField;
Expand All @@ -865,7 +871,9 @@ private function getFileFormField($xpath)
try {
$fileFormField = new FileFormField($element);
} catch (\LogicException $e) {
throw new DriverException(sprintf('Impossible to check the element with XPath "%s" as it is not a file form field.', $xpath));
throw new DriverException(
sprintf('Impossible to check the element with XPath "%s" as it is not a file form field.', $xpath)
);
}

return $fileFormField;
Expand All @@ -886,7 +894,9 @@ private function getTextareaFormField($xpath)
try {
$textareaFormField = new TextareaFormField($element);
} catch (\LogicException $e) {
throw new DriverException(sprintf('Impossible to check the element with XPath "%s" as it is not a textarea.', $xpath));
throw new DriverException(
sprintf('Impossible to check the element with XPath "%s" as it is not a textarea.', $xpath)
);
}

return $textareaFormField;
Expand Down Expand Up @@ -950,7 +960,10 @@ private function getCrawler(): Crawler

private function getJsNode(string $xpath): string
{
return sprintf('document.evaluate(`%s`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue', $xpath);
return sprintf(
'document.evaluate(`%s`, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue',
$xpath
);
}

private function toCoordinates(string $xpath): WebDriverCoordinates
Expand Down

0 comments on commit 7cbc07a

Please sign in to comment.