OrExpression::evaluate()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 1
nop 1
dl 20
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace PeacefulBit\Slate\Parser\Nodes;
4
5
use function Nerd\Common\Arrays\toHeadTail;
6
use function Nerd\Common\Functional\tail;
7
use PeacefulBit\Slate\Core\Frame;
8
9
class OrExpression extends Node
10
{
11
    private $expressions;
12
13
    public function __construct(array $expressions)
14
    {
15
        $this->expressions = $expressions;
16
    }
17
18
    /**
19
     * @return array
20
     */
21
    public function getExpressions(): array
22
    {
23
        return $this->expressions;
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function __toString()
30
    {
31
        return '(or ' . implode(' ', array_map('strval', $this->expressions)) . ')';
32
    }
33
34
    /**
35
     * @param Frame $frame
36
     * @return mixed
37
     */
38 View Code Duplication
    public function evaluate(Frame $frame)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $iter = tail(function ($rest) use (&$iter, $frame) {
41
            if (empty($rest)) {
42
                return false;
43
            }
44
45
            list ($head, $tail) = toHeadTail($rest);
46
47
            $result = $frame($head);
48
49
            if ($result) {
50
                return $result;
51
            }
52
53
            return $iter($tail);
54
        });
55
56
        return $iter($this->getExpressions());
57
    }
58
}
59