Completed
Push — master ( 74ffa0...ed410a )
by Mariano
10:21
created

NodeBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 58
wmc 6
lcom 1
cbo 3
ccs 28
cts 28
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A addCondition() 0 8 1
A addActionIfConditionMatches() 0 5 1
A addActionIfConditionDoesNotMatch() 0 5 1
A withConditionOperator() 0 5 1
A build() 0 9 1
1
<?php
2
namespace Mcustiel\PowerRoute\Utils;
3
4
use Mcustiel\PowerRoute\Common\ConfigOptions;
5
6
class NodeBuilder
7
{
8
    use StaticCreation;
9
10
    const CONDITION_OPERATOR_ONE = ConfigOptions::CONFIG_NODE_CONDITION_ONE;
11
    const CONDITION_OPERATOR_ALL = ConfigOptions::CONFIG_NODE_CONDITION_ALL;
12
13
    private $conditions;
14
    private $operator;
15
    private $actions;
16
17 1
    public function __construct()
18
    {
19 1
        $this->conditions = [];
20 1
        $this->actions = [
21 1
            ConfigOptions::CONFIG_NODE_ACTIONS_MATCH => [],
22 1
            ConfigOptions::CONFIG_NODE_ACTIONS_NOTMATCH => []
23 1
        ];
24 1
        $this->operator = self::CONDITION_OPERATOR_ONE;
25 1
    }
26
27 1
    public function addCondition(InputSourceBuilder $inputSourceBuilder, MatcherBuilder $matcherBuilder)
28
    {
29 1
        $this->conditions[] = [
30 1
            ConfigOptions::CONFIG_NODE_CONDITION_MATCHER => $matcherBuilder->build(),
31 1
            ConfigOptions::CONFIG_NODE_CONDITION_SOURCE => $inputSourceBuilder->build(),
32
        ];
33 1
        return $this;
34
    }
35
36 1
    public function addActionIfConditionMatches($name, $argument)
37
    {
38 1
        $this->actions[ConfigOptions::CONFIG_NODE_ACTIONS_MATCH][] = [$name => $argument];
39 1
        return $this;
40
    }
41
42 1
    public function addActionIfConditionDoesNotMatch($name, $argument)
43
    {
44 1
        $this->actions[ConfigOptions::CONFIG_NODE_ACTIONS_NOTMATCH][] = [$name => $argument];
45 1
        return $this;
46
    }
47
48 1
    public function withConditionOperator($operator)
49
    {
50 1
        $this->operator = $operator;
51 1
        return $this;
52
    }
53
54 1
    public function build()
55
    {
56
        return [
57 1
            ConfigOptions::CONFIG_NODE_CONDITION => [
58 1
                $this->operator => $this->conditions,
59 1
            ],
60 1
            ConfigOptions::CONFIG_NODE_ACTIONS =>  $this->actions
61 1
        ];
62
    }
63
}
64