VariableParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 6
cts 14
cp 0.4286
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 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