Test Failed
Push — master ( 3eb0e4...9196b6 )
by Ivan
02:13
created

MatchVoter::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Everlution\Navigation\Voter;
6
7
/**
8
 * Class MatchVoter.
9
 * @author Ivan Barlog <[email protected]>
10
 */
11
abstract class MatchVoter implements Voter
12
{
13
    /**
14
     * @param string $haystack
15
     * @param Matchable $item
16
     * @return bool
17
     */
18
    public function match(string $haystack, Matchable &$item): bool
19
    {
20
        foreach ($item->getMatches() as $match) {
21
            if (null !== ($needle = $match->accept($this))) {
22
                return $this->matches($haystack, $needle);
23
            }
24
        }
25
26
        return false;
27
    }
28
29
    /**
30
     * @param string $haystack
31
     * @param string $needle
32
     * @return bool
33
     */
34
    abstract protected function matches(string $haystack, string $needle): bool;
35
}
36