GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch api-revamp (c37467)
by Yusuf
02:04
created

MicrodataDocumentParser::getTopLevelItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace YusufKandemir\MicrodataParser;
4
5
class MicrodataDocumentParser
6
{
7
    /** @var \DOMDocument */
8
    protected $dom;
9
10
    /** @var \DOMXPath */
11
    protected $xpath;
12
13
    /** @var MicrodataElementParser */
14
    protected $elementParser;
15
16
    /**
17
     * MicrodataParser constructor.
18
     *
19
     * @param \DOMDocument $dom DOMDocument to be parsed
20
     * @param MicrodataElementParser|null $elementParser
21
     */
22 39
    public function __construct(\DOMDocument $dom, MicrodataElementParser $elementParser = null)
23
    {
24 39
        $this->dom = $dom;
25 39
        $this->xpath = new \DOMXPath($this->dom);
26
27 39
        $this->elementParser = $elementParser ?? new MicrodataElementParser;
28 39
    }
29
30
    /**
31
     * Parses microdata and returns result as object
32
     *
33
     * @return \stdClass
34
     */
35 39
    public function parse() : \stdClass
36
    {
37 39
        $result = new \stdClass;
38
39 39
        $result->items = [];
40
41 39
        foreach ($this->getTopLevelItems() as $item) {
42 39
            $result->items[] = $this->elementParser->parse($item);
43
        }
44
45 39
        return $result;
46
    }
47
48
    /**
49
     * Finds top level items in document
50
     *
51
     * @see https://www.w3.org/TR/2018/WD-microdata-20180426/#dfn-top-level-microdata-item
52
     *
53
     * @return \DOMNodeList
54
     */
55 39
    protected function getTopLevelItems() : \DOMNodeList
56
    {
57 39
        return $this->xpath->query('//*[@itemscope and not(@itemprop)]');
58
    }
59
}
60