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

XmlFileLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getSourceFilePath() 0 3 1
A getData() 0 3 1
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