VariableParser::make()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
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 3
    public function __construct(VariableFactory $factory)
10
    {
11 3
        $this->factory = $factory;
12 3
        $this->factory->setVariableParser($this);
13 3
    }
14
15 3
    public static function make(VariableFactory $factory): VariableParser
16
    {
17 3
        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->getParsed();
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