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

ServiceAwareMatcherFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 4
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * @license For full copyright and license information view LICENSE file distributed with this source code.
4
 */
5
namespace eZ\Bundle\EzPublishCoreBundle\Matcher;
6
7
use eZ\Publish\API\Repository\Repository;
8
use eZ\Publish\Core\MVC\Symfony\Matcher\ClassNameMatcherFactory;
9
10
/**
11
 * A view matcher factory that also accepts services as matchers.
12
 *
13
 * If a service id is passed as the MatcherIdentifier, this service will be used for the matching.
14
 * Otherwise, it will fallback to the class name based matcher factory.
15
 */
16
final class ServiceAwareMatcherFactory extends ClassNameMatcherFactory
17
{
18
    /** @var \eZ\Bundle\EzPublishCoreBundle\Matcher\ViewMatcherRegistry */
19
    private $viewMatcherRegistry;
20
21
    public function __construct(
22
        ViewMatcherRegistry $viewMatcherRegistry,
23
        Repository $repository,
24
        $relativeNamespace = null,
25
        array $matchConfig = []
26
    ) {
27
        $this->viewMatcherRegistry = $viewMatcherRegistry;
28
29
        parent::__construct($repository, $relativeNamespace, $matchConfig);
30
    }
31
32
    /**
33
     * @param string $matcherIdentifier
34
     *
35
     * @return \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MatcherInterface
36
     */
37
    protected function getMatcher($matcherIdentifier)
38
    {
39
        if (strpos($matcherIdentifier, '@') === 0) {
40
            return $this->viewMatcherRegistry->getMatcher(substr($matcherIdentifier, 1));
41
        }
42
43
        return parent::getMatcher($matcherIdentifier);
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::getMatcher($matcherIdentifier); of type eZ\Publish\Core\MVC\Symf...er\ViewMatcherInterface adds the type eZ\Publish\Core\MVC\Symf...er\ViewMatcherInterface to the return on line 43 which is incompatible with the return type documented by eZ\Bundle\EzPublishCoreB...cherFactory::getMatcher of type eZ\Publish\Core\MVC\Symf...tBased\MatcherInterface.
Loading history...
44
    }
45
}
46