Conditions | 7 |
Paths | 6 |
Total Lines | 25 |
Lines | 25 |
Ratio | 100 % |
Changes | 0 |
1 | <?php |
||
27 | public function parse(DOMDocument $dom, DOMXPath $xpath) : DateTimeImmutable |
||
28 | { |
||
29 | // This expression does not work. It looks like the reason is the array-notation... |
||
30 | //$endDate = $xpath->query('//div[contains(text()[2], "event ends")]/following-sibling::h2'); |
||
31 | $startDate = $xpath->query('//div[contains(text(), "event ends")]'); |
||
32 | |||
33 | if (! $startDate || $startDate->length == 0) { |
||
34 | // This expression does not work. It looks like the reason is the array-notation... |
||
35 | //$endDate = $xpath->query('//div[contains(text()[2], "event date")]/following-sibling::h2'); |
||
36 | $startDate = $xpath->query('//div[contains(text(), "event date")]'); |
||
37 | } |
||
38 | if (! $startDate || $startDate->length == 0) { |
||
39 | throw new \InvalidArgumentException('The Event does not seem to have an end date'); |
||
40 | } |
||
41 | |||
42 | $endDate = $xpath->query('h2', $startDate->item(0)->parentNode); |
||
43 | |||
44 | if (! $startDate || $startDate->length == 0) { |
||
45 | throw new \InvalidArgumentException('The Event does not seem to have an end date'); |
||
46 | } |
||
47 | |||
48 | $endDate = $endDate->item(0)->textContent; |
||
49 | |||
50 | return new DateTimeImmutable($endDate, $this->timezone); |
||
51 | } |
||
52 | } |
||
53 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.