| Total Complexity | 8 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | } |
||
| 51 |