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

VariableParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A make() 0 4 1
A parse() 0 12 2
A getVariable() 0 4 1
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