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

NodeBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
crap 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