YamlFile::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
namespace ConfigTree\FileParsing\Formats;
3
4
use ConfigTree\FileParsing\ArrayableFile;
5
use ConfigTree\FileParsing\Reading\FileContentsRetriever;
6
use Symfony\Component\Yaml\Parser as YamlParser;
7
8
class YamlFile implements ArrayableFile
9
{
10
    /** @var string */
11
    private $path;
12
13
    /** @var FileContentsRetriever */
14
    private $fileContentsRetriever;
15
16
    /** @var YamlParser */
17
    private $yamlParser;
18
19
    public function __construct(string $path, FileContentsRetriever $fileContentsRetriever, YamlParser $yamlParser)
20
    {
21
        $this->path                  = $path;
22
        $this->fileContentsRetriever = $fileContentsRetriever;
23
        $this->yamlParser            = $yamlParser;
24
    }
25
26
    /**
27
     * @return array
28
     */
29
    public function toArray() : array
30
    {
31
        $fileContents = $this->fileContentsRetriever->fileGetContents($this->path);
32
        return $this->yamlParser->parse($fileContents);
33
    }
34
}
35