Skip to content

Commit

Permalink
move unserializeResult() back and fix phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
robocoder committed Mar 19, 2024
1 parent d385444 commit 83b6840
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
63 changes: 0 additions & 63 deletions lib/WebDriver/AbstractWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,69 +154,6 @@ protected function serializeArguments(array $arguments)
return $arguments;
}

/**
* Unserialize result (containing web elements and/or shadow roots)
*
* @param mixed $result
*
* @return mixed
*/
protected function unserializeResult($result)
{
$element = is_array($result) ? $this->makeElement($result) : null;

if ($element !== null) {
return $element;
}

if (is_array($result)) {
foreach ($result as $key => $value) {
$result[$key] = $this->unserializeResult($value);
}
}

return $result;
}

/**
* Factory method for elements
*
* @param array $value
*
* @return \WebDriver\Element|\WebDriver\Shadow|null
*/
protected function makeElement($value)
{
if (array_key_exists(LegacyElement::LEGACY_ELEMENT_ID, $value)) {
$identifier = $value[LegacyElement::LEGACY_ELEMENT_ID];

return new LegacyElement(
$this->getIdentifierPath('/element/' . $identifier),
$identifier
);
}

if (array_key_exists(Element::WEB_ELEMENT_ID, $value)) {
$identifier = $value[Element::WEB_ELEMENT_ID];

return new Element(
$this->getIdentifierPath('/element/' . $identifier),
$identifier
);
}

if (array_key_exists(Shadow::SHADOW_ROOT_ID, $value)) {
$identifier = $value[Shadow::SHADOW_ROOT_ID];

return new Shadow(
$this->getIdentifierPath('/shadow/' . $identifier),
$identifier
);
}

return null;
}

/**
* Curl request to webdriver server.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/WebDriver/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getID()
/**
* Get the value of an element's attribute: /session/:sessionId/element/:id/attribute/:name
*
* @param string name
* @param string $name
*
* @return mixed
*/
Expand Down
63 changes: 63 additions & 0 deletions lib/WebDriver/Execute.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,69 @@ public function sync(array $jsonScript)
return $this->unserializeResult($result['value']);
}

/**
* Unserialize result (containing web elements and/or shadow roots)
*
* @param mixed $result
*
* @return mixed
*/
protected function unserializeResult($result)
{
$element = is_array($result) ? $this->makeElement($result) : null;

if ($element !== null) {
return $element;
}

if (is_array($result)) {
foreach ($result as $key => $value) {
$result[$key] = $this->unserializeResult($value);
}
}

return $result;
}

/**
* Factory method for elements
*
* @param array $value
*
* @return \WebDriver\Element|\WebDriver\Shadow|null
*/
protected function makeElement($value)
{
if (array_key_exists(LegacyElement::LEGACY_ELEMENT_ID, $value)) {
$identifier = $value[LegacyElement::LEGACY_ELEMENT_ID];

return new LegacyElement(
$this->getIdentifierPath('/element/' . $identifier),
$identifier
);
}

if (array_key_exists(Element::WEB_ELEMENT_ID, $value)) {
$identifier = $value[Element::WEB_ELEMENT_ID];

return new Element(
$this->getIdentifierPath('/element/' . $identifier),
$identifier
);
}

if (array_key_exists(Shadow::SHADOW_ROOT_ID, $value)) {
$identifier = $value[Shadow::SHADOW_ROOT_ID];

return new Shadow(
$this->getIdentifierPath('/shadow/' . $identifier),
$identifier
);
}

return null;
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/WebDriver/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function open($url)
*/
public function capabilities()
{
if (! isset($this->capabilities)) {
if ($this->capabilities === null) {
$result = $this->curl('GET', '');

$this->capabilities = $result['value'];
Expand Down

0 comments on commit 83b6840

Please sign in to comment.