Conditions | 3 |
Paths | 2 |
Total Lines | 12 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 3 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
38 | 17 | public function selectLink(string $search, int $position = 0): Link |
|
39 | { |
||
40 | 17 | $elements = $this->crawler->filterXPath('//a')->reduce( |
|
41 | 17 | fn (Crawler $linkElement): bool => |
|
42 | 17 | ('' !== $text = $linkElement->text('')) && fnmatch($search, $text, FNM_CASEFOLD) |
|
43 | 17 | ); |
|
44 | |||
45 | 17 | if ($elements->count() > $position) { |
|
46 | 17 | return $elements->eq($position)->link(); |
|
47 | } |
||
48 | |||
49 | 1 | throw new RuntimeException(sprintf('Link text "%s" [%d] was not found', $search, $position)); |
|
50 | } |
||
52 |