Skip to content

Commit

Permalink
simplify private
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 18, 2022
1 parent 91314b2 commit 2a6eff2
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/Element/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ public function waitFor($timeout, $callback)
*
* @return NodeElement[]
*/
private function findAllWithLimit($selector, $locator, ?int $limit): array
private function findAllWithLimit($selector, $locator, bool $firstOnly): array
{
if ('named' === $selector) {
$items = $this->findAllWithLimit('named_exact', $locator, $limit);
$items = $this->findAllWithLimit('named_exact', $locator, $firstOnly);
if (empty($items)) {
$items = $this->findAllWithLimit('named_partial', $locator, $limit);
$items = $this->findAllWithLimit('named_partial', $locator, $firstOnly);
}

return $items;
Expand All @@ -158,12 +158,8 @@ private function findAllWithLimit($selector, $locator, ?int $limit): array
$xpath = $this->selectorsHandler->selectorToXpath($selector, $locator);
$xpath = $this->xpathManipulator->prepend($xpath, $this->getXpath());

if ($limit !== null) {
if ($limit === 1) {
$xpath = '(' . $xpath . ')[1]';
} else {
$xpath = '(' . $xpath . ')[position() <= ' . $limit . ']';
}
if ($firstOnly) {
$xpath = '(' . $xpath . ')[1]';
}

return $this->getDriver()->find($xpath);
Expand All @@ -174,7 +170,7 @@ private function findAllWithLimit($selector, $locator, ?int $limit): array
*/
public function find($selector, $locator)
{
$items = $this->findAllWithLimit($selector, $locator, 1);
$items = $this->findAllWithLimit($selector, $locator, true);

return count($items) > 0 ? current($items) : null;
}
Expand All @@ -184,7 +180,7 @@ public function find($selector, $locator)
*/
public function findAll($selector, $locator)
{
return $this->findAllWithLimit($selector, $locator, null);
return $this->findAllWithLimit($selector, $locator, false);
}

/**
Expand Down

0 comments on commit 2a6eff2

Please sign in to comment.