SharedStrings   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A readNext() 0 12 3
A process() 0 6 1
1
<?php declare(strict_types = 1);
2
3
namespace Spaghetti\XLSXParser;
4
5
use XMLReader;
6
7
use function strtr;
8
use function trim;
9
10
/**
11
 * @internal
12
 */
13
final class SharedStrings extends AbstractXMLDictionary
14
{
15
    private const INDEX = 'si';
16
    private const VALUE = 't';
17
18
    private int $currentIndex = -1;
19
20
    protected function readNext(): void
21
    {
22
        $xml = $this->getXMLReader();
23
24
        while ($xml->read()) {
25
            if (XMLReader::ELEMENT === $xml->nodeType) {
26
                $this->process(xml: $xml);
27
            }
28
        }
29
30
        $this->valid = false;
31
        $this->closeXMLReader();
32
    }
33
34
    private function process(XMLReader $xml): void
35
    {
36
        match ($xml->name) {
37
            self::INDEX => $this->currentIndex++,
38
            self::VALUE => $this->values[$this->currentIndex][] = trim(string: strtr($xml->readString(), ["\u{a0}" => ' ']), characters: ' '),
39
            default => null,
40
        };
41
    }
42
}
43