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

VariableParser::getVariable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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