Completed
Pull Request — master (#328)
by
unknown
07:15
created

EventTypeResolver   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  
B __construct() 0 25 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\Event;
4
5
use CultuurNet\UDB3\Offer\TypeResolverInterface;
6
use ValueObjects\StringLiteral\StringLiteral;
7
8
class EventTypeResolver implements TypeResolverInterface
9
{
10
    /**
11
     * @var EventType[]
12
     */
13
    private $types;
14
15
    public function __construct()
16
    {
17
        $this->types = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('0.7.0.0.0' => new...'Theatervoorstelling')) 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...
18
            "0.7.0.0.0" => new EventType("0.7.0.0.0", "Begeleide rondleiding"),
19
            "0.6.0.0.0" => new EventType("0.6.0.0.0", "Beurs"),
20
            "0.50.4.0.0" => new EventType("0.50.4.0.0", "Concert"),
21
            "0.3.1.0.0" => new EventType("0.3.1.0.0", "Cursus of workshop"),
22
            "0.54.0.0.0" => new EventType("0.54.0.0.0", "Dansvoorstelling"),
23
            "1.50.0.0.0" => new EventType("1.50.0.0.0", "Eten en drinken"),
24
            "0.5.0.0.0" => new EventType("0.5.0.0.0", "Festival"),
25
            "0.50.6.0.0" => new EventType("0.50.6.0.0", "Film"),
26
            "0.57.0.0.0" => new EventType("0.57.0.0.0", "Kamp of vakantie"),
27
            "0.28.0.0.0" => new EventType("0.28.0.0.0", "Kermis of feestelijkheid"),
28
            "0.3.2.0.0" => new EventType("0.3.2.0.0", "Lezing of congres"),
29
            "0.37.0.0.0" => new EventType("0.37.0.0.0", "Markt of braderie"),
30
            "0.12.0.0.0" => new EventType("0.12.0.0.0", "Opendeurdag"),
31
            "0.49.0.0.0" => new EventType("0.49.0.0.0", "Party of fuif"),
32
            "0.17.0.0.0" => new EventType("0.17.0.0.0", "Route"),
33
            "0.50.21.0.0" => new EventType("0.50.21.0.0", "Spel of quiz"),
34
            "0.59.0.0.0 " => new EventType("0.59.0.0.0 ", "Sport en beweging"),
35
            "0.19.0.0.0" => new EventType("0.19.0.0.0", "Sportwedstrijd bekijken"),
36
            "0.0.0.0.0" => new EventType("0.0.0.0.0", "Tentoonstelling"),
37
            "0.55.0.0.0" => new EventType("0.55.0.0.0", "Theatervoorstelling"),
38
        ];
39
    }
40
41 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...
42
    {
43
        if (!array_key_exists((string) $typeId, $this->types)) {
44
            throw new \Exception("Unknown event type id: " . $typeId);
45
        }
46
        return $this->types[(string) $typeId];
47
    }
48
}
49