Completed
Push — master ( 2e4917...2e950a )
by Klaus
19:05 queued 19:05
created

IfElseControlNode   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Linio\Component\RuleEngine\Ast;
6
7
class IfElseControlNode extends Node
8
{
9
    /**
10
     * @var IfControlNode[]
11
     */
12
    protected array $conditionalExpressions = [];
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
13
    protected ?Node $elseStatement;
14
15
    /**
16
     * @param IfControlNode[] $conditionalExpressions
17
     */
18
    public function __construct(array $conditionalExpressions, Node $elseStatement = null)
19
    {
20
        $this->conditionalExpressions = $conditionalExpressions;
21
        $this->elseStatement = $elseStatement;
22
    }
23
24
    public function evaluate()
25
    {
26
        foreach ($this->conditionalExpressions as $conditionalExpression) {
27
            if ($conditionalExpression->evaluate()) {
28
                return;
29
            }
30
        }
31
32
        if ($this->elseStatement) {
33
            $this->elseStatement->evaluate();
34
        }
35
    }
36
}
37