Passed
Pull Request — master (#14)
by
unknown
02:46
created

YamlLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 27
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isSupported() 0 3 1
A load() 0 7 2
A unload() 0 3 1
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
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 0 found
Loading history...
11
    {
12 3
        return class_exists(Parser::class);
13
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
14
15
    /** @var Parser */
16
    private $parser;
0 ignored issues
show
Coding Style introduced by
Private member variable "parser" must contain a leading underscore
Loading history...
17
18 3
    public function __construct(Parser $parser = null)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
19
    {
20 3
        $this->parser = $parser ?? new Parser();
21 3
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
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
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
31
32
    public function unload(string $path, array $data) {
0 ignored issues
show
Coding Style introduced by
Expected 0 blank lines after opening function brace; 1 found
Loading history...
33
        
34
        throw LoaderException::notSupportedMethod('unload', static::class);
35
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
36
}
37