Passed
Push — master ( 8e4c63...0fda03 )
by
unknown
05:01
created

PickupLocation::setModuleId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Thelia\Model;
4
5
use Symfony\Component\Serializer\Encoder\JsonEncoder;
6
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
7
use Symfony\Component\Serializer\Serializer;
8
use Thelia\Core\Translation\Translator;
9
10
class PickupLocation  {
11
12
    /** OPENING HOURS ARRAY KEYS */
13
    const MONDAY_OPENING_HOURS_KEY = '0';
14
    const TUESDAY_OPENING_HOURS_KEY = '1';
15
    const WEDNESDAY_OPENING_HOURS_KEY = '2';
16
    const THURSDAY_OPENING_HOURS_KEY = '3';
17
    const FRIDAY_OPENING_HOURS_KEY = '4';
18
    const SATURDAY_OPENING_HOURS_KEY = '5';
19
    const SUNDAY_OPENING_HOURS_KEY = '6';
20
21
    /** @var string */
22
    protected $id = null;
23
24
    /** @var float */
25
    protected $latitude = null;
26
27
    /** @var float */
28
    protected $longitude = null;
29
30
    /** @var string */
31
    protected $title = null;
32
33
    /** @var integer */
34
    protected $moduleId = null;
35
36
    /** @var array */
37
    protected $openingHours = [
38
        self::MONDAY_OPENING_HOURS_KEY => null,
39
        self::TUESDAY_OPENING_HOURS_KEY => null,
40
        self::WEDNESDAY_OPENING_HOURS_KEY => null,
41
        self::THURSDAY_OPENING_HOURS_KEY => null,
42
        self::FRIDAY_OPENING_HOURS_KEY => null,
43
        self::SATURDAY_OPENING_HOURS_KEY => null,
44
        self::SUNDAY_OPENING_HOURS_KEY => null
45
    ];
46
47
    /**
48
     * @var PickupLocationAddress
49
     */
50
    protected $address = null;
51
52
    public function __construct() {
53
        $this->serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
0 ignored issues
show
Bug Best Practice introduced by
The property serializer does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getId()
60
    {
61
        return $this->id;
62
    }
63
64
    /**
65
     * @param string $id
66
     * @return PickupLocation
67
     */
68
    public function setId($id)
69
    {
70
        $this->id = $id;
71
        return $this;
72
    }
73
74
    /** @return float */
75
    public function getLatitude()
76
    {
77
        return $this->latitude;
78
    }
79
80
    /** @param float
81
     *  @return $this
82
     * */
83
    public function setLatitude($latitude)
84
    {
85
        $this->latitude = $latitude;
86
        return $this;
87
    }
88
89
    /** @return float */
90
    public function getLongitude()
91
    {
92
        return $this->longitude;
93
    }
94
95
    /** @param float
96
     * @return $this|PickupLocation
97
     * */
98
    public function setLongitude($longitude)
99
    {
100
        $this->longitude = $longitude;
101
        return $this;
102
    }
103
104
    /** @return string */
105
    public function getTitle()
106
    {
107
        return $this->title;
108
    }
109
110
    /** @param string
111
     *  @return $this|PickupLocation
112
     * */
113
    public function setTitle($title)
114
    {
115
        $this->title = $title;
116
        return $this;
117
    }
118
119
    /**
120
     * @return PickupLocationAddress
121
     */
122
    public function getAddress()
123
    {
124
        return $this->address;
125
    }
126
127
    /**
128
     * @param PickupLocationAddress $address
129
     *
130
     * @return PickupLocation
131
     */
132
    public function setAddress($address)
133
    {
134
        $this->address = $address;
135
        return $this;
136
    }
137
138
    /**
139
     * @return int
140
     */
141
    public function getModuleId()
142
    {
143
        return $this->moduleId;
144
    }
145
146
    /**
147
     * @param int $moduleId
148
     * @return PickupLocation
149
     */
150
    public function setModuleId($moduleId)
151
    {
152
        $this->moduleId = $moduleId;
153
154
        return $this;
155
    }
156
157
    /**
158
     * @return array
159
     */
160
    public function getOpeningHours()
161
    {
162
        return $this->openingHours;
163
    }
164
165
    /**
166
     * @param integer $day
167
     * @param string $hours
168
     *
169
     * @return $this
170
     * @throws \Exception
171
     */
172
    public function setOpeningHours($day, $hours)
173
    {
174
        if (!array_key_exists($day, $this->openingHours)) {
175
            throw new \Exception(Translator::getInstance()->trans('Tried to set the opening hours for a non existant day in the array. Please use the constants defined in the PickupLocation class.'));
176
        }
177
178
        $this->openingHours[$day] = $hours;
179
180
        return $this;
181
    }
182
183
    /**
184
     * @return array
185
     * */
186
    public function toArray() {
187
        return json_decode($this->serializer->serialize($this, 'json'), true);
188
    }
189
}                    
190