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

YamlFileLoader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 38
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 Symfony\Component\Yaml\Yaml;
9
use Webmozart\Assert\Assert;
10
11
/**
12
 * YAML File Loader
13
 */
14
final class YamlFileLoader implements LoaderInterface
15
{
16
    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...
17
    private array $data;
18
19
    public function __construct(string $filePath)
20
    {
21
        Assert::fileExists($filePath);
22
        $this->filePath = $filePath;
23
24
        $fileContent = file_get_contents($filePath);
25
        Assert::string($fileContent);
26
27
        $this->data = Yaml::parse($fileContent, Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE + Yaml::PARSE_OBJECT);
28
    }
29
30
    public function getData(): array
31
    {
32
        return $this->data;
33
    }
34
35
    public function getSourceFilePath(): string
36
    {
37
        return $this->filePath;
38
    }
39
}
40