Passed
Push — spaghetti ( fcb196...2528e5 )
by simpletoimplement
02:19
created

Relationships::storeRelationshipTarget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Relationships::getStylesPath() 0 3 1
1
<?php declare(strict_types = 1);
2
3
namespace Spaghetti\XLSXParser;
4
5
use XMLReader;
6
7
use function basename;
8
9
/**
10
 * @internal
11
 */
12
final class Relationships extends AbstractXMLResource
13
{
14
    private array $workSheetPaths = [];
15
    private string $sharedStringPath = '';
16
    private string $stylePath = '';
17
18
    public function __construct(string $path)
19
    {
20
        parent::__construct(path: $path);
21
        $xml = $this->getXMLReader();
22
23
        while ($xml->read()) {
24
            if (XMLReader::ELEMENT === $xml->nodeType && 'Relationship' === $xml->name) {
25
                $target = 'xl/' . $xml->getAttribute(name: 'Target');
26
27
                match (basename(path: (string) $xml->getAttribute(name: 'Type'))) {
28
                    'worksheet' => $this->workSheetPaths[$xml->getAttribute(name: 'Id')] = $target,
29
                    'styles' => $this->stylePath = $target,
30
                    'sharedStrings' => $this->sharedStringPath = $target,
31
                    default => null,
32
                };
33
            }
34
        }
35
36
        $this->closeXMLReader();
37
    }
38
39
    public function getWorksheetPath(string $rId): string
40
    {
41
        return $this->workSheetPaths[$rId];
42
    }
43
44
    public function getSharedStringsPath(): string
45
    {
46
        return $this->sharedStringPath;
47
    }
48
49
    public function getStylesPath(): string
50
    {
51
        return $this->stylePath;
52
    }
53
}
54