Completed
Push — ezp-30882-thumbnail ( 274ed9...d4335b )
by
unknown
14:43
created

ViewMatcherRegistry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 34
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() 4 4 1
A setMatcher() 4 4 1
A getMatcher() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\ViewMatcherInterface;
12
13 View Code Duplication
final class ViewMatcherRegistry
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /** @var \eZ\Publish\Core\MVC\Symfony\Matcher\ViewMatcherInterface[] */
16
    private $matchers;
17
18
    /**
19
     * @param \eZ\Publish\Core\MVC\Symfony\Matcher\ViewMatcherInterface[] $matchers
20
     */
21
    public function __construct(array $matchers = [])
22
    {
23
        $this->matchers = $matchers;
24
    }
25
26
    public function setMatcher(string $matcherIdentifier, ViewMatcherInterface $matcher): void
27
    {
28
        $this->matchers[$matcherIdentifier] = $matcher;
29
    }
30
31
    /**
32
     * @param string $matcherIdentifier
33
     *
34
     * @return \eZ\Publish\Core\MVC\Symfony\Matcher\ViewMatcherInterface
35
     *
36
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
37
     */
38
    public function getMatcher(string $matcherIdentifier): ViewMatcherInterface
39
    {
40
        if (!isset($this->matchers[$matcherIdentifier])) {
41
            throw new NotFoundException('Matcher', $matcherIdentifier);
42
        }
43
44
        return $this->matchers[$matcherIdentifier];
45
    }
46
}
47