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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 53
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTopLevelItems() 0 3 1
A __construct() 0 6 1
A parse() 0 11 2
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