Completed
Push — master ( ca8025...177d87 )
by Łukasz
14:26
created

ViewMatcherRegistry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setMatcher() 0 4 1
A getMatcher() 0 8 2
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
declare(strict_types=1);
7
8
namespace eZ\Bundle\EzPublishCoreBundle\Matcher;
9
10
use eZ\Publish\Core\Base\Exceptions\NotFoundException;
11
use eZ\Publish\Core\MVC\Symfony\Matcher\MatcherInterface;
12
13
final class ViewMatcherRegistry
14
{
15
    /** @var \eZ\Publish\Core\MVC\Symfony\Matcher\MatcherInterface[] */
16
    private $matchers;
17
18
    /**
19
     * @param \eZ\Publish\Core\MVC\Symfony\Matcher\MatcherInterface[] $matchers
20
     */
21
    public function __construct(array $matchers = [])
22
    {
23
        $this->matchers = $matchers;
24
    }
25
26
    public function setMatcher(string $matcherIdentifier, MatcherInterface $matcher): void
27
    {
28
        $this->matchers[$matcherIdentifier] = $matcher;
29
    }
30
31
    /**
32
     * @param string $matcherIdentifier
33
     *
34
     * @return \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MatcherInterface
35
     *
36
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
37
     */
38
    public function getMatcher(string $matcherIdentifier): MatcherInterface
39
    {
40
        if (!isset($this->matchers[$matcherIdentifier])) {
41
            throw new NotFoundException('Matcher', $matcherIdentifier);
42
        }
43
44
        return $this->matchers[$matcherIdentifier];
45
    }
46
}
47