Skip to content

Commit 2a6eff2

Browse files
committed
simplify private
1 parent 91314b2 commit 2a6eff2

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

src/Element/Element.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ public function waitFor($timeout, $callback)
144144
*
145145
* @return NodeElement[]
146146
*/
147-
private function findAllWithLimit($selector, $locator, ?int $limit): array
147+
private function findAllWithLimit($selector, $locator, bool $firstOnly): array
148148
{
149149
if ('named' === $selector) {
150-
$items = $this->findAllWithLimit('named_exact', $locator, $limit);
150+
$items = $this->findAllWithLimit('named_exact', $locator, $firstOnly);
151151
if (empty($items)) {
152-
$items = $this->findAllWithLimit('named_partial', $locator, $limit);
152+
$items = $this->findAllWithLimit('named_partial', $locator, $firstOnly);
153153
}
154154

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

161-
if ($limit !== null) {
162-
if ($limit === 1) {
163-
$xpath = '(' . $xpath . ')[1]';
164-
} else {
165-
$xpath = '(' . $xpath . ')[position() <= ' . $limit . ']';
166-
}
161+
if ($firstOnly) {
162+
$xpath = '(' . $xpath . ')[1]';
167163
}
168164

169165
return $this->getDriver()->find($xpath);
@@ -174,7 +170,7 @@ private function findAllWithLimit($selector, $locator, ?int $limit): array
174170
*/
175171
public function find($selector, $locator)
176172
{
177-
$items = $this->findAllWithLimit($selector, $locator, 1);
173+
$items = $this->findAllWithLimit($selector, $locator, true);
178174

179175
return count($items) > 0 ? current($items) : null;
180176
}
@@ -184,7 +180,7 @@ public function find($selector, $locator)
184180
*/
185181
public function findAll($selector, $locator)
186182
{
187-
return $this->findAllWithLimit($selector, $locator, null);
183+
return $this->findAllWithLimit($selector, $locator, false);
188184
}
189185

190186
/**

0 commit comments

Comments
 (0)