Passed
Branch master (609f2f)
by Dorian
08:59
created

XmlFileLoader::getSourceFilePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gnutix\Library\Loader;
6
7
use Gnutix\Library\LoaderInterface;
8
use SimpleXMLElement;
9
use Webmozart\Assert\Assert;
10
11
final class XmlFileLoader implements LoaderInterface
12
{
13
    private string $filePath;
14
    private SimpleXMLElement $data;
15
16
    public function __construct(string $filePath)
17
    {
18
        Assert::fileExists($filePath);
19
        $this->filePath = $filePath;
20
21
        $fileContent = file_get_contents($filePath);
22
        Assert::string($fileContent);
23
24
        $simpleXmlElement = simplexml_load_string($fileContent);
25
        Assert::isInstanceOf($simpleXmlElement, SimpleXMLElement::class);
26
27
        $this->data = $simpleXmlElement;
28
    }
29
30
    public function getData(): SimpleXMLElement
31
    {
32
        return $this->data;
33
    }
34
35
    public function getSourceFilePath(): string
36
    {
37
        return $this->filePath;
38
    }
39
}
40