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

LabelEventRelationTypeResolver::getRelationType()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 4
nop 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\LabelEventInterface;
10
11
class LabelEventRelationTypeResolver implements LabelEventRelationTypeResolverInterface
12
{
13
    /**
14
     * @var LabelEventIsOfEventType
15
     */
16
    private $eventTypeSpecification;
17
18
    /**
19
     * @var LabelEventIsOfPlaceType
20
     */
21
    private $placeTypeSpecification;
22
23
    /**
24
     * @var LabelEventIsOfOrganizerType
25
     */
26
    private $organizerTypeSpecification;
27
28
    public function __construct()
29
    {
30
        $this->eventTypeSpecification = new LabelEventIsOfEventType();
31
        $this->placeTypeSpecification = new LabelEventIsOfPlaceType();
32
        $this->organizerTypeSpecification = new LabelEventIsOfOrganizerType();
33
    }
34
35
    /**
36
     * @param LabelEventInterface $labelEvent
37
     * @return RelationType
38
     * @throws \InvalidArgumentException
39
     */
40
    public function getRelationType(LabelEventInterface $labelEvent)
41
    {
42
        if ($this->eventTypeSpecification->isSatisfiedBy($labelEvent)) {
43
            $relationType = RelationType::EVENT();
44
        } else if ($this->placeTypeSpecification->isSatisfiedBy($labelEvent)) {
45
            $relationType = RelationType::PLACE();
46
        } else if ($this->organizerTypeSpecification->isSatisfiedBy($labelEvent)) {
47
            $relationType = RelationType::ORGANIZER();
48
        } else {
49
            $message = $this->createIllegalArgumentMessage($labelEvent);
50
            throw new \InvalidArgumentException($message);
51
        }
52
53
        return $relationType;
54
    }
55
56
    /**
57
     * @param LabelEventInterface $labelEvent
58
     * @return string
59
     */
60
    private function createIllegalArgumentMessage($labelEvent)
61
    {
62
        return 'Event with type ' . get_class($labelEvent) . ' can not be converted to a relation type!';
63
    }
64
}
65