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

AndExpr   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 8
c 1
b 0
f 0
dl 0
loc 33
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 9 3
A add() 0 3 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 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