Passed
Branch v2 (aaaa8e)
by Brent
03:38
created

VariableParser::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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