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

VariableParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Stitcher\Variable;
4
5
class VariableParser
6
{
7
    private $factory;
8
9 30
    public function __construct(VariableFactory $factory)
10
    {
11 30
        $this->factory = $factory;
12 30
        $this->factory->setVariableParser($this);
13 30
    }
14
15 29
    public static function make(VariableFactory $factory): VariableParser
16
    {
17 29
        return new self($factory);
18
    }
19
20 21
    public function parse($unparsedValue)
21
    {
22 21
        $variable = $this->factory->create($unparsedValue);
23
24 21
        if ($variable) {
25 21
            $parsedValue = $variable->parsed();
26
        } else {
27
            $parsedValue = $unparsedValue;
28
        }
29
30 21
        return $parsedValue;
31
    }
32
33 16
    public function getVariable($unparsedValue): AbstractVariable
34
    {
35 16
        return $this->factory->create($unparsedValue);
36
    }
37
}
38