Passed
Push — master ( fba5ec...ac8f64 )
by Ivan
02:15
created

VoterContainer::isMatch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Everlution\Navigation\Match;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_MATCH, expecting T_STRING on line 5 at column 32
Loading history...
6
7
use Everlution\Navigation\Item\MatchableInterface;
8
9
/**
10
 * Class VoterContainer.
11
 *
12
 * @author Ivan Barlog <[email protected]>
13
 */
14
class VoterContainer implements UrlMatchVoterInterface
15
{
16
    /** @var VoterInterface[] */
17
    private $voters = [];
18
19
    public function __construct(array $voters = [])
20
    {
21
        array_map([$this, 'addVoter'], $voters);
22
    }
23
24
    public function addVoter(VoterInterface $voter): void
25
    {
26
        $this->voters[] = $voter;
27
    }
28
29
    public function matches(string $url, MatchableInterface $item): bool
30
    {
31
        foreach ($item->getMatches() as $match) {
32
            if ($this->isMatch($url, $match)) {
33
                return true;
34
            }
35
        }
36
37
        return false;
38
    }
39
40
    private function isMatch(string $url, MatchInterface $match): bool
41
    {
42
        foreach ($this->voters as $voter) {
43
            if ($voter->matches($url, $match)) {
44
                return true;
45
            }
46
        }
47
48
        return false;
49
    }
50
}
51