Completed
Pull Request — master (#37)
by Andreas
01:34
created

EventUri::parse()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.3554
c 0
b 0
f 0
cc 5
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * Copyright Andrea Heigl <[email protected]>
7
 *
8
 * Licenses under the MIT-license. For details see the included file LICENSE.md
9
 */
10
namespace Callingallpapers\Subcommands\Sessionize\Parser;
11
12
use DOMDocument;
13
use DOMXPath;
14
15
class EventUri
16
{
17
18
    public function parse(DOMDocument $dom, DOMXPath $xpath)
0 ignored issues
show
Unused Code introduced by
The parameter $dom is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
    {
20
        // This expression does not work. It looks like the reason is the array-notation...
21
        //$uriPath = $xpath->query('//div[contains(text()[2], "website")]/following-sibling::h2/a');
22
        $uriPath = $xpath->query('//div[contains(., "website")]');
23
24
        if (! $uriPath || $uriPath->length == 0) {
25
            throw new \InvalidArgumentException('The CfP does not seem to have an EventUri');
26
        }
27
28
        $uriPath = $xpath->query('//h2/a', $uriPath->item(0)->parentNode);
29
30
        if (! $uriPath || $uriPath->length == 0) {
31
            throw new \InvalidArgumentException('The Event does not seem to have a location');
32
        }
33
34
        return $uriPath->item(0)->attributes->getNamedItem('href')->textContent;
35
    }
36
}
37