Completed
Push — master ( 513898...595f7b )
by Łukasz
29:17
created

PlaceholderProviderRegistry   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 36
loc 36
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A addProvider() 4 4 1
A supports() 4 4 1
A getProvider() 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
/**
4
 * This file is part of the eZ Publish Kernel package.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\Imagine;
10
11
use InvalidArgumentException;
12
13 View Code Duplication
class PlaceholderProviderRegistry
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
    /**
16
     * @var \eZ\Bundle\EzPublishCoreBundle\Imagine\PlaceholderProvider
17
     */
18
    private $providers;
19
20
    /**
21
     * PlaceholderProviderRegistry constructor.
22
     *
23
     * @param array $providers
24
     */
25
    public function __construct(array $providers = [])
26
    {
27
        $this->providers = $providers;
0 ignored issues
show
Documentation Bug introduced by
It seems like $providers of type array is incompatible with the declared type object<eZ\Bundle\EzPubli...ne\PlaceholderProvider> of property $providers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28
    }
29
30
    public function addProvider(string $type, PlaceholderProvider $provider)
31
    {
32
        $this->providers[$type] = $provider;
33
    }
34
35
    public function supports(string $type): bool
36
    {
37
        return isset($this->providers[$type]);
38
    }
39
40
    public function getProvider(string $type): PlaceholderProvider
41
    {
42
        if (!$this->supports($type)) {
43
            throw new InvalidArgumentException("Unknown placeholder provider: $type");
44
        }
45
46
        return $this->providers[$type];
47
    }
48
}
49