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

Location   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 28 7
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 Location
16
{
17
    public function parse(DOMDocument $dom, DOMXPath $xpath) : string
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...
18
    {
19
        // This expression does not work. It looks like the reason is the array-notation...
20
        //$locations = $xpath->query('//div[contains(text()[2], "location")]/following-sibling::h2/span');
21
        $locationMarker = $xpath->query("//div[contains(., 'location')]");
22
        if (! $locationMarker || $locationMarker->length == 0) {
23
            throw new \InvalidArgumentException('The Event does not seem to have a locationMarker');
24
        }
25
26
        $locations = $xpath->query('//h2/span', $locationMarker->item(0)->parentNode);
27
28
        if (! $locations || $locations->length == 0) {
29
            throw new \InvalidArgumentException('The Event does not seem to have a location');
30
        }
31
        $location = [];
32
        foreach ($locations as $item) {
33
            $location = trim($item->textContent);
34
            if ($location === '') {
35
                continue;
36
            }
37
38
            return $location;
39
40
            $location[] = $location;
0 ignored issues
show
Unused Code introduced by
$location[] = $location; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
41
        }
42
43
        return implode(', ', array_unique($location));
44
    }
45
}
46