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.

StreamingReader   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 91
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A read() 0 12 2
A preRead() 0 8 2
A postRead() 0 4 1
A cursorHasElement() 0 5 2
A readNext() 0 11 2
A moveToNextElement() 0 8 3
1
<?php
2
3
namespace UCD\Infrastructure\Repository\CharacterRepository\XMLRepository\CodepointElementReader;
4
5
use UCD\Infrastructure\Repository\CharacterRepository\XMLRepository\CodepointElementReader;
6
use UCD\Infrastructure\Repository\CharacterRepository\XMLRepository\XMLReader;
7
8
final class StreamingReader implements CodepointElementReader
9
{
10
    const ELEMENT_CHARACTER = 'char';
11
    const ELEMENT_NON_CHARACTER = 'noncharacter';
12
    const ELEMENT_SURROGATE = 'surrogate';
13
14
    /**
15
     * @var array
16
     */
17
    private static $elements = [
18
        self::ELEMENT_CHARACTER => true,
19
        self::ELEMENT_NON_CHARACTER => true,
20
        self::ELEMENT_SURROGATE => true
21
    ];
22
23
    /**
24
     * @var XMLReader
25
     */
26
    private $xmlReader;
27
28
    /**
29
     * @param XMLReader $xmlReader
30
     */
31
    public function __construct(XMLReader $xmlReader)
32
    {
33
        $this->xmlReader = $xmlReader;
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function read()
40
    {
41
        $this->preRead();
42
43
        try {
44
            while ($element = $this->readNext()) {
45
                yield $element;
46
            }
47
        } finally {
48
            $this->postRead();
49
        }
50
    }
51
52
    private function preRead()
53
    {
54
        $this->xmlReader->reopen();
55
56
        while ($this->cursorHasElement() !== true) {
57
            $this->xmlReader->read();
58
        }
59
    }
60
61
    private function postRead()
62
    {
63
        $this->xmlReader->close();
64
    }
65
66
    /**
67
     * @return bool
68
     */
69
    private function cursorHasElement()
70
    {
71
        return $this->xmlReader->nodeType === XMLReader::ELEMENT
72
            && array_key_exists($this->xmlReader->name, self::$elements);
73
    }
74
75
    /**
76
     * @return \DOMElement|null
77
     */
78
    private function readNext()
79
    {
80
        if (!$this->cursorHasElement()) {
81
            return null;
82
        }
83
84
        $element = $this->xmlReader->expand();
85
        $this->moveToNextElement();
86
87
        return $element;
88
    }
89
90
    private function moveToNextElement()
91
    {
92
        while ($this->xmlReader->next() !== false) {
93
            if ($this->cursorHasElement()) {
94
                break;
95
            }
96
        }
97
    }
98
}