YamlLoader   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isSupported() 0 4 1
A __construct() 0 4 1
A load() 0 8 2
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