NodeBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

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