Completed
Pull Request — master (#239)
by Luc
04:59
created

LabelEventRelationTypeResolver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getRelationType() 0 15 4
A createIllegalArgumentMessage() 0 4 1
1
<?php
2
3
namespace CultuurNet\UDB3\Label;
4
5
use CultuurNet\UDB3\Label\Specifications\LabelEventIsOfEventType;
6
use CultuurNet\UDB3\Label\Specifications\LabelEventIsOfOrganizerType;
7
use CultuurNet\UDB3\Label\Specifications\LabelEventIsOfPlaceType;
8
use CultuurNet\UDB3\Label\ValueObjects\RelationType;
9
use CultuurNet\UDB3\Offer\Events\AbstractLabelEvent as EventAbstractLabelEvent;
10
use CultuurNet\UDB3\Organizer\Events\AbstractLabelEvent as OrganizerAbstractLabelEvent;
11
12
class LabelEventRelationTypeResolver implements LabelEventRelationTypeResolverInterface
13
{
14
    /**
15
     * @var LabelEventIsOfEventType
16
     */
17
    private $eventTypeSpecification;
18
19
    /**
20
     * @var LabelEventIsOfPlaceType
21
     */
22
    private $placeTypeSpecification;
23
24
    /**
25
     * @var LabelEventIsOfOrganizerType
26
     */
27
    private $organizerTypeSpecification;
28
29
    public function __construct()
30
    {
31
        $this->eventTypeSpecification = new LabelEventIsOfEventType();
32
        $this->placeTypeSpecification = new LabelEventIsOfPlaceType();
33
        $this->organizerTypeSpecification = new LabelEventIsOfOrganizerType();
34
    }
35
36
    /**
37
     * @param EventAbstractLabelEvent|OrganizerAbstractLabelEvent $labelEvent
38
     * @return RelationType
39
     * @throws \InvalidArgumentException
40
     */
41
    public function getRelationType($labelEvent)
42
    {
43
        if ($this->eventTypeSpecification->isSatisfiedBy($labelEvent)) {
0 ignored issues
show
Bug introduced by
It seems like $labelEvent defined by parameter $labelEvent on line 41 can also be of type object<CultuurNet\UDB3\O...nts\AbstractLabelEvent>; however, CultuurNet\UDB3\Label\Sp...ntType::isSatisfiedBy() does only seem to accept object<CultuurNet\UDB3\O...nts\AbstractLabelEvent>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
44
            $relationType = RelationType::EVENT();
45
        } else if ($this->placeTypeSpecification->isSatisfiedBy($labelEvent)) {
0 ignored issues
show
Bug introduced by
It seems like $labelEvent defined by parameter $labelEvent on line 41 can also be of type object<CultuurNet\UDB3\O...nts\AbstractLabelEvent>; however, CultuurNet\UDB3\Label\Sp...ceType::isSatisfiedBy() does only seem to accept object<CultuurNet\UDB3\O...nts\AbstractLabelEvent>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
46
            $relationType = RelationType::PLACE();
47
        } else if ($this->organizerTypeSpecification->isSatisfiedBy($labelEvent)) {
0 ignored issues
show
Bug introduced by
It seems like $labelEvent defined by parameter $labelEvent on line 41 can also be of type object<CultuurNet\UDB3\O...nts\AbstractLabelEvent>; however, CultuurNet\UDB3\Label\Sp...erType::isSatisfiedBy() does only seem to accept object<CultuurNet\UDB3\O...nts\AbstractLabelEvent>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
48
            $relationType = RelationType::ORGANIZER();
49
        } else {
50
            $message = $this->createIllegalArgumentMessage($labelEvent);
51
            throw new \InvalidArgumentException($message);
52
        }
53
54
        return $relationType;
55
    }
56
57
    /**
58
     * @param EventAbstractLabelEvent|OrganizerAbstractLabelEvent $labelEvent
59
     * @return string
60
     */
61
    private function createIllegalArgumentMessage($labelEvent)
62
    {
63
        return 'Event with type ' . get_class($labelEvent) . ' can not be converted to a relation type!';
64
    }
65
}
66