Completed
Pull Request — master (#296)
by Luc
08:35 queued 03:51
created

OpeningHour::getCloses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace CultuurNet\UDB3\Calendar;
4
5
use Broadway\Serializer\SerializableInterface;
6
7
class OpeningHour implements SerializableInterface
8
{
9
    /**
10
     * @var OpeningTime
11
     */
12
    private $opens;
13
14
    /**
15
     * @var OpeningTime
16
     */
17
    private $closes;
18
19
    /**
20
     * @var DayOfWeekCollection
21
     */
22
    private $dayOfWeekCollection;
23
24
    /**
25
     * OpeningHour constructor.
26
     * @param OpeningTime $opens
27
     * @param OpeningTime $closes
28
     * @param DayOfWeekCollection $dayOfWeekCollection
29
     */
30
    public function __construct(
31
        OpeningTime $opens,
32
        OpeningTime $closes,
33
        DayOfWeekCollection $dayOfWeekCollection
34
    ) {
35
        $this->dayOfWeekCollection = $dayOfWeekCollection;
36
        $this->opens = $opens;
37
        $this->closes = $closes;
38
    }
39
40
    /**
41
     * @return OpeningTime
42
     */
43
    public function getOpens()
44
    {
45
        return $this->opens;
46
    }
47
48
    /**
49
     * @return OpeningTime
50
     */
51
    public function getCloses()
52
    {
53
        return $this->closes;
54
    }
55
56
    /**
57
     * @return DayOfWeekCollection
58
     */
59
    public function getDayOfWeekCollection()
60
    {
61
        return $this->dayOfWeekCollection;
62
    }
63
64
    /**
65
     * @param DayOfWeekCollection $dayOfWeekCollection
66
     */
67
    public function addDayOfWeekCollection(DayOfWeekCollection $dayOfWeekCollection)
68
    {
69
        foreach ($dayOfWeekCollection->getDaysOfWeek() as $dayOfWeek) {
70
            $this->dayOfWeekCollection->addDayOfWeek($dayOfWeek);
71
        }
72
    }
73
74
    /**
75
     * @param OpeningHour $otherOpeningHour
76
     * @return bool
77
     */
78
    public function hasEqualHours(OpeningHour $otherOpeningHour)
79
    {
80
        return $otherOpeningHour->getOpens()->sameValueAs($this->getOpens()) &&
81
            $otherOpeningHour->getCloses()->sameValueAs($this->getCloses());
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87
    public static function deserialize(array $data)
88
    {
89
        return new static(
90
            OpeningTime::fromNativeString($data['opens']),
91
            OpeningTime::fromNativeString($data['closes']),
92
            DayOfWeekCollection::deserialize($data['dayOfWeek'])
93
        );
94
    }
95
96
    /**
97
     * @inheritdoc
98
     */
99
    public function serialize()
100
    {
101
        return [
102
            'opens' => $this->opens->toNativeString(),
103
            'closes' => $this->closes->toNativeString(),
104
            'dayOfWeek' => $this->dayOfWeekCollection->serialize()
105
        ];
106
    }
107
}
108