Conditions | 7 |
Paths | 6 |
Total Lines | 25 |
Lines | 25 |
Ratio | 100 % |
Changes | 0 |
1 | <?php |
||
26 | public function parse(DOMDocument $dom, DOMXPath $xpath) : DateTimeImmutable |
||
27 | { |
||
28 | // This expression does not work. It looks like the reason is the array-notation... |
||
29 | //$startDate = $xpath->query('//div[contains(text()[2], "event starts")]/following-sibling::h2'); |
||
30 | $startDate = $xpath->query('//div[contains(., "event starts")]'); |
||
31 | |||
32 | if (! $startDate || $startDate->length == 0) { |
||
33 | // This expression does not work. It looks like the reason is the array-notation... |
||
34 | //$startDate = $xpath->query('//div[contains(text()[2], "event date")]/following-sibling::h2'); |
||
35 | $startDate = $xpath->query('//div[contains(., "event date")]'); |
||
36 | } |
||
37 | if (! $startDate || $startDate->length == 0) { |
||
38 | throw new \InvalidArgumentException('The Event does not seem to have a start date-identifier'); |
||
39 | } |
||
40 | |||
41 | $startDate = $xpath->query('h2', $startDate->item($startDate->length-1)->parentNode); |
||
42 | |||
43 | if (! $startDate || $startDate->length == 0) { |
||
44 | throw new \InvalidArgumentException('The Event does not seem to have a start date'); |
||
45 | } |
||
46 | |||
47 | $startDate = $startDate->item(0)->textContent; |
||
48 | |||
49 | return new DateTimeImmutable($startDate, $this->timezone); |
||
50 | } |
||
51 | } |
||
52 |
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.