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

AndExpr::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 3
nc 3
nop 1
crap 3
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 AndExpr 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 33
    public function __construct(callable ...$expressions)
33
    {
34 33
        $this->conditions = $expressions;
35 33
    }
36
37
    /**
38
     * @param callable(Node): bool $expression
39
     */
40 27
    public function add(callable $expression): void
41
    {
42 27
        $this->conditions[] = $expression;
43 27
    }
44
45 33
    public function __invoke(Node $node): bool
46
    {
47 33
        foreach ($this->conditions as $condition) {
48 27
            if (! $condition($node)) {
49 27
                return false;
50
            }
51
        }
52
53 27
        return true;
54
    }
55
}
56