Completed
Push — latest ( ca3ef7...2db11b )
by Colin
15s queued 10s
created

OrExpr::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Node\Query;
15
16
use League\CommonMark\Node\Node;
17
18
/**
19
 * @internal
20
 */
21
final class OrExpr implements ExpressionInterface
22
{
23
    /**
24
     * @var callable[]
25
     * @psalm-var list<callable(Node): bool>
26
     */
27
    private $conditions;
28
29
    /**
30
     * @psalm-param callable(Node): bool $expressions
31
     */
32 9
    public function __construct(callable ...$expressions)
33
    {
34 9
        $this->conditions = $expressions;
35 9
    }
36
37
    /**
38
     * @param callable(Node): bool $expression
39
     */
40 3
    public function add(callable $expression): void
41
    {
42 3
        $this->conditions[] = $expression;
43 3
    }
44
45 9
    public function __invoke(Node $node): bool
46
    {
47 9
        foreach ($this->conditions as $condition) {
48 9
            if ($condition($node)) {
49 9
                return true;
50
            }
51
        }
52
53 9
        return false;
54
    }
55
}
56