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

MatchVoter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 10 3
matches() 0 1 ?
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