Passed
Push — develop ( ec1e42...80559e )
by Brent
03:22
created

YamlVariable   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 46
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A make() 0 4 1
A parse() 0 8 1
A parseRecursive() 0 18 4
1
<?php
2
3
namespace Stitcher\Variable;
4
5
use Stitcher\File;
6
use Symfony\Component\Yaml\Yaml;
7
8
class YamlVariable extends AbstractVariable
9
{
10
    private $parser;
11
    private $variableParser;
12
13 17
    public function __construct(string $unparsed, Yaml $parser, VariableParser $variableParser)
14
    {
15 17
        parent::__construct($unparsed);
16
17 17
        $this->parser = $parser;
18 17
        $this->variableParser = $variableParser;
19 17
    }
20
21 17
    public static function make(string $value, Yaml $parser, VariableParser $variableParser): YamlVariable
22
    {
23 17
        return new self($value, $parser, $variableParser);
24
    }
25
26 16
    public function parse(): AbstractVariable
27
    {
28 16
        $this->parsed = $this->parser->parse(File::read($this->unparsed));
29
30 16
        $this->parsed = $this->parseRecursive($this->parsed);
31
32 16
        return $this;
33
    }
34
35 16
    private function parseRecursive($unparsedValue)
36
    {
37 16
        $unparsedValue = $this->variableParser->getVariable($unparsedValue);
38
39 16
        if ($unparsedValue instanceof DefaultVariable) {
40 16
            $parsedValue = $unparsedValue->parsed();
41
42 16
            if (is_array($parsedValue)) {
43 16
                foreach ($parsedValue as $key => &$property) {
44 16
                    $property = $this->parseRecursive($property);
45
                }
46
            }
47
        } else {
48 9
            $parsedValue = $unparsedValue->parsed();
49
        }
50
51 16
        return $parsedValue;
52
    }
53
}
54