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

LabelEventRelationTypeResolver::getRelationType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\Label;
4
5
use CultuurNet\UDB3\Label\Specifications\LabelEventIsOfEventType;
6
use CultuurNet\UDB3\Label\Specifications\LabelEventIsOfPlaceType;
7
use CultuurNet\UDB3\Label\ValueObjects\RelationType;
8
use CultuurNet\UDB3\Offer\Events\AbstractLabelEvent;
9
10
class LabelEventRelationTypeResolver implements LabelEventRelationTypeResolverInterface
11
{
12
    /**
13
     * @var LabelEventIsOfEventType
14
     */
15
    private $eventTypeSpecification;
16
17
    /**
18
     * @var LabelEventIsOfPlaceType
19
     */
20
    private $placeTypeSpecification;
21
22
    public function __construct()
23
    {
24
        $this->eventTypeSpecification = new LabelEventIsOfEventType();
25
        $this->placeTypeSpecification = new LabelEventIsOfPlaceType();
26
    }
27
28
    /**
29
     * @param AbstractLabelEvent $labelEvent
30
     * @return RelationType
31
     * @throws \InvalidArgumentException
32
     */
33
    public function getRelationType($labelEvent)
34
    {
35
        if ($this->eventTypeSpecification->isSatisfiedBy($labelEvent)) {
36
            $offerType = RelationType::EVENT();
37
        } else if ($this->placeTypeSpecification->isSatisfiedBy($labelEvent)) {
38
            $offerType = RelationType::PLACE();
39
        } else {
40
            $message = $this->createIllegalArgumentMessage($labelEvent);
41
            throw new \InvalidArgumentException($message);
42
        }
43
44
        return $offerType;
45
    }
46
47
    /**
48
     * @param AbstractLabelEvent $labelEvent
49
     * @return string
50
     */
51
    private function createIllegalArgumentMessage(AbstractLabelEvent $labelEvent)
52
    {
53
        return 'Event with type ' . get_class($labelEvent) . ' can not be converted to a relation type!';
54
    }
55
}
56