Completed
Push — master ( af09d7...7599bb )
by Dorian
02:06
created

XmlFileLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
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