Conditions | 6 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | public function closest(string $selector, Crawler $crawler): ?Crawler |
||
15 | { |
||
16 | if (!count($crawler)) { |
||
17 | throw new InvalidArgumentException(self::CURRENT_NODE_LIST_EMPTY); |
||
18 | } |
||
19 | |||
20 | $node = $crawler->getNode(0); |
||
21 | |||
22 | if ($node !== null) { |
||
23 | while ($node = $node->parentNode) { |
||
24 | if (XML_ELEMENT_NODE === $node->nodeType) { |
||
25 | $parentCrawler = new Crawler($node, $crawler->getUri(), $crawler->getBaseHref()); |
||
26 | $descendantMatchingSelector = $parentCrawler->filter($selector); |
||
27 | if ($descendantMatchingSelector->count()) { |
||
28 | return $descendantMatchingSelector; |
||
29 | } |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 | |||
34 | return null; |
||
35 | } |
||
37 |