IfExpression::getConsequent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PeacefulBit\Slate\Parser\Nodes;
4
5
use PeacefulBit\Slate\Core\Frame;
6
7
class IfExpression extends Node
8
{
9
    private $test;
10
    private $consequent;
11
    private $alternative;
12
13
    public function __construct(Node $test, Node $consequent, Node $alternative)
14
    {
15
        $this->test = $test;
16
        $this->consequent = $consequent;
17
        $this->alternative = $alternative;
18
    }
19
20
    /**
21
     * @return Node
22
     */
23
    public function getTest(): Node
24
    {
25
        return $this->test;
26
    }
27
28
    /**
29
     * @return Node
30
     */
31
    public function getConsequent(): Node
32
    {
33
        return $this->consequent;
34
    }
35
36
    /**
37
     * @return Node
38
     */
39
    public function getAlternative(): Node
40
    {
41
        return $this->alternative;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function __toString()
48
    {
49
        return '(if '
50
        . strval($this->getTest())
51
        . ' '
52
        . strval($this->getConsequent())
53
        . ' '
54
        . strval($this->getAlternative())
55
        . ')';
56
    }
57
58
    /**
59
     * @param Frame $frame
60
     * @return mixed
61
     */
62
    public function evaluate(Frame $frame)
63
    {
64
        $test = $frame($this->test);
65
        return $frame($test ? $this->consequent : $this->alternative);
66
    }
67
}
68