YamlLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\Config\Loader;
5
6
use Symfony\Component\Yaml\Parser;
7
8
class YamlLoader implements LoaderInterface
9
{
10 3
    public static function isSupported(): bool
11
    {
12 3
        return class_exists(Parser::class);
13
    }
14
15
    /** @var Parser */
16
    private $parser;
17
18 3
    public function __construct(Parser $parser = null)
19
    {
20 3
        $this->parser = $parser ?? new Parser();
21 3
    }
22
23 2
    public function load(string $path): array
24
    {
25 2
        if (is_file("$path.yaml")) {
26 2
            return $this->parser->parse(file_get_contents("$path.yaml"));
27
        }
28
29 2
        return [];
30
    }
31
}
32