Completed
Pull Request — master (#328)
by Luc
04:54
created

PlaceTypeResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 17.07 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 7
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 22 1
A byId() 7 7 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
namespace CultuurNet\UDB3\Place;
4
5
use CultuurNet\UDB3\Event\EventType;
6
use CultuurNet\UDB3\Offer\TypeResolverInterface;
7
use ValueObjects\StringLiteral\StringLiteral;
8
9
class PlaceTypeResolver implements TypeResolverInterface
10
{
11
    /**
12
     * @var EventType[]
13
     */
14
    private $types;
15
16
    public function __construct()
17
    {
18
        $this->types = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('0.14.0.0.0' => ne...0', 'Openbare ruimte')) of type array<string,object<Cult...3\\Event\\EventType>"}> is incompatible with the declared type array<integer,object<Cul...\UDB3\Event\EventType>> of property $types.

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...
19
            "0.14.0.0.0" => new EventType("0.14.0.0.0", "Monument"),
20
            "0.15.0.0.0" => new EventType("0.15.0.0.0", "Natuur, park of tuin"),
21
            "3CuHvenJ" => new EventType("3CuHvenJ", "Archeologische Site"),
22
            "GnPFp9uvOUyqhOckIFMKmg" => new EventType("GnPFp9uvOUyqhOckIFMKmg", "Museum of galerij"),
23
            "kI7uAyn2uUu9VV6Z3uWZTA" => new EventType("kI7uAyn2uUu9VV6Z3uWZTA", "Bibliotheek of documentatiecentrum"),
24
            "0.53.0.0.0" => new EventType("0.53.0.0.0", "Recreatiedomein of centrum"),
25
            "0.41.0.0.0" => new EventType("0.41.0.0.0", "Thema of pretpark"),
26
            "rJRFUqmd6EiqTD4c7HS90w" => new EventType("rJRFUqmd6EiqTD4c7HS90w", "School of onderwijscentrum"),
27
            "eBwaUAAhw0ur0Z02i5ttnw" => new EventType("eBwaUAAhw0ur0Z02i5ttnw", "Sportcentrum"),
28
            "VRC6HX0Wa063sq98G5ciqw" => new EventType("VRC6HX0Wa063sq98G5ciqw", "Winkel"),
29
            "JCjA0i5COUmdjMwcyjNAFA" => new EventType("JCjA0i5COUmdjMwcyjNAFA", "Jeugdhuis of jeugdcentrum"),
30
            "Yf4aZBfsUEu2NsQqsprngw" => new EventType("Yf4aZBfsUEu2NsQqsprngw", "Cultuur- of ontmoetingscentrum"),
31
            "YVBc8KVdrU6XfTNvhMYUpg" => new EventType("YVBc8KVdrU6XfTNvhMYUpg", "Discotheek"),
32
            "BtVNd33sR0WntjALVbyp3w" => new EventType("BtVNd33sR0WntjALVbyp3w", "Bioscoop"),
33
            "ekdc4ATGoUitCa0e6me6xA" => new EventType("ekdc4ATGoUitCa0e6me6xA", "Horeca"),
34
            "OyaPaf64AEmEAYXHeLMAtA" => new EventType("OyaPaf64AEmEAYXHeLMAtA", "Zaal of expohal"),
35
            "0.8.0.0.0" => new EventType("0.8.0.0.0", "Openbare ruimte"),
36
        ];
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 View Code Duplication
    public function byId(StringLiteral $typeId)
0 ignored issues
show
Duplication introduced by
This method 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...
43
    {
44
        if (!array_key_exists((string) $typeId, $this->types)) {
45
            throw new \Exception("Unknown place type id: " . $typeId);
46
        }
47
        return $this->types[(string) $typeId];
48
    }
49
}
50