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

YamlFileLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
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;
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