Passed
Push — master ( 973b57...8e4c63 )
by
unknown
05:03
created

DeliveryPostageEvent::setMaximumDeliveryDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
13
14
namespace Thelia\Core\Event\Delivery;
15
16
use Thelia\Core\Event\ActionEvent;
17
use Thelia\Core\Translation\Translator;
18
use Thelia\Model\Address;
19
use Thelia\Model\Cart;
20
use Thelia\Model\Country;
21
use Thelia\Model\OrderPostage;
22
use Thelia\Model\State;
23
use Thelia\Module\DeliveryModuleInterface;
24
25
/**
26
 * Class DeliveryPostageEvent
27
 * @package Thelia\Core\Event\Delivery
28
 * @author Julien Chanséaume <[email protected]>
29
 */
30
class DeliveryPostageEvent extends ActionEvent
31
{
32
    /** @var AbstractDeliveryModule */
0 ignored issues
show
Bug introduced by
The type Thelia\Core\Event\Delivery\AbstractDeliveryModule was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
    protected $module = null;
34
35
    /** @var Cart */
36
    protected $cart = null;
37
38
    /** @var Address */
39
    protected $address = null;
40
41
    /** @var Country */
42
    protected $country = null;
43
44
    /** @var State */
45
    protected $state = null;
46
47
    /** @var bool */
48
    protected $validModule = false;
49
50
    /** @var OrderPostage|null */
51
    protected $postage = null;
52
53
    /**
54
     * @deprecated deprecated since version 2.4.1 use min and max deliver date instead
55
     * @var \DateTime|null
56
     */
57
    protected $deliveryDate = null;
58
59
    /**
60
     * @var \DateTime|null
61
     */
62
    protected $minimumDeliveryDate = null;
63
64
    /**
65
     * @var \DateTime|null
66
     */
67
    protected $maximumDeliveryDate = null;
68
69
    /**
70
     * @var string
71
     */
72
    protected $deliveryMode = null;
73
74
    /** @var array */
75
    protected $additionalData = [];
76
77
    /**
78
     * DeliveryPostageEvent constructor.
79
     * @param DeliveryModuleInterface $module
80
     * @param Country $country
81
     * @param Cart $cart
82
     * @param State $state
83
     */
84
    public function __construct(
85
        DeliveryModuleInterface $module,
86
        Cart $cart,
87
        Address $address = null,
88
        Country $country = null,
89
        State $state = null
90
    ) {
91
        $this->module = $module;
0 ignored issues
show
Documentation Bug introduced by
It seems like $module of type Thelia\Module\DeliveryModuleInterface is incompatible with the declared type Thelia\Core\Event\Delivery\AbstractDeliveryModule of property $module.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
92
        $this->cart = $cart;
93
        $this->address = $address;
94
        $this->country = $country;
95
        $this->state = $state;
96
    }
97
98
    /**
99
     * @return Cart
100
     */
101
    public function getCart()
102
    {
103
        return $this->cart;
104
    }
105
106
    /**
107
     * @param Cart $cart
108
     */
109
    public function setCart($cart)
110
    {
111
        $this->cart = $cart;
112
        return $this;
113
    }
114
115
    /**
116
     * @return Address
117
     */
118
    public function getAddress()
119
    {
120
        return $this->address;
121
    }
122
123
    /**
124
     * @param Address $address
125
     */
126
    public function setAddress($address)
127
    {
128
        $this->address = $address;
129
        return $this;
130
    }
131
132
    /**
133
     * @deprecated deprecated since version 2.4.1 use min and max deliver date instead
134
     * @return \DateTime|null
135
     */
136
    public function getDeliveryDate()
137
    {
138
        return $this->deliveryDate;
0 ignored issues
show
Deprecated Code introduced by
The property Thelia\Core\Event\Delive...ageEvent::$deliveryDate has been deprecated: deprecated since version 2.4.1 use min and max deliver date instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

138
        return /** @scrutinizer ignore-deprecated */ $this->deliveryDate;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
139
    }
140
141
    /**
142
     * @deprecated deprecated since version 2.4.1 use min and max deliver date instead
143
     * @param \DateTime|null $deliveryDate
144
     */
145
    public function setDeliveryDate($deliveryDate)
146
    {
147
        $this->deliveryDate = $deliveryDate;
0 ignored issues
show
Deprecated Code introduced by
The property Thelia\Core\Event\Delive...ageEvent::$deliveryDate has been deprecated: deprecated since version 2.4.1 use min and max deliver date instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

147
        /** @scrutinizer ignore-deprecated */ $this->deliveryDate = $deliveryDate;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
148
        return $this;
149
    }
150
151
    /**
152
     * @return AbstractDeliveryModule
153
     */
154
    public function getModule()
155
    {
156
        return $this->module;
157
    }
158
159
    /**
160
     * @param AbstractDeliveryModule $module
161
     */
162
    public function setModule($module)
163
    {
164
        $this->module = $module;
165
        return $this;
166
    }
167
168
    /**
169
     * @return null|OrderPostage
170
     */
171
    public function getPostage()
172
    {
173
        return $this->postage;
174
    }
175
176
    /**
177
     * @param null|double|OrderPostage $postage
178
     */
179
    public function setPostage($postage)
180
    {
181
        $this->postage = OrderPostage::loadFromPostage($postage);
182
        return $this;
183
    }
184
185
    /**
186
     * @return boolean
187
     */
188
    public function isValidModule()
189
    {
190
        return $this->validModule;
191
    }
192
193
    /**
194
     * @param boolean $validModule
195
     */
196
    public function setValidModule($validModule)
197
    {
198
        $this->validModule = $validModule;
199
        return $this;
200
    }
201
202
    /**
203
     * @return bool
204
     */
205
    public function hasAdditionalData()
206
    {
207
        return \count($this->additionalData) > 0;
208
    }
209
210
    /**
211
     * @return array
212
     */
213
    public function getAdditionalData()
214
    {
215
        return $this->additionalData;
216
    }
217
218
    /**
219
     * @param array $additionalData
220
     */
221
    public function setAdditionalData($additionalData)
222
    {
223
        $this->additionalData = $additionalData;
224
        return $this;
225
    }
226
227
    /**
228
     * @param string $key the key of the additional data
229
     * @param mixed $value the value of the additional data
230
     *
231
     * return $this
232
     */
233
    public function addAdditionalData($key, $value)
234
    {
235
        $this->additionalData[$key] = $value;
236
237
        return $this;
238
    }
239
240
    /**
241
     * @return Country|null
242
     */
243
    public function getCountry()
244
    {
245
        return $this->getAddress() !== null ? $this->getAddress()->getCountry() : $this->country;
246
    }
247
248
    /**
249
     * @return State|null
250
     */
251
    public function getState()
252
    {
253
        return $this->getAddress() !== null ? $this->getAddress()->getState() : $this->state;
254
    }
255
256
    /**
257
     * @return mixed
258
     */
259
    public function getDeliveryMode()
260
    {
261
        return $this->deliveryMode;
262
    }
263
264
    /**
265
     * @param mixed $deliveryMode
266
     *
267
     * @return DeliveryPostageEvent
268
     * @throws \Exception
269
     */
270
    public function setDeliveryMode($deliveryMode)
271
    {
272
        if (!in_array($deliveryMode, ['pickup', 'delivery'])) {
273
            throw new \Exception(Translator::getInstance()->trans('A delivery module can only de of type pickup or delivery'));
274
        }
275
276
        $this->deliveryMode = $deliveryMode;
277
        return $this;
278
    }
279
280
    /**
281
     * @return \DateTime|null
282
     */
283
    public function getMinimumDeliveryDate()
284
    {
285
        return $this->minimumDeliveryDate;
286
    }
287
288
    /**
289
     * @param \DateTime|null $minimumDeliveryDate
290
     *
291
     * @return DeliveryPostageEvent
292
     */
293
    public function setMinimumDeliveryDate($minimumDeliveryDate)
294
    {
295
        $this->minimumDeliveryDate = $minimumDeliveryDate;
296
        return $this;
297
    }
298
299
    /**
300
     * @return \DateTime|null
301
     */
302
    public function getMaximumDeliveryDate()
303
    {
304
        return $this->maximumDeliveryDate;
305
    }
306
307
    /**
308
     * @param \DateTime|null $maximumDeliveryDate
309
     *
310
     * @return DeliveryPostageEvent
311
     */
312
    public function setMaximumDeliveryDate($maximumDeliveryDate)
313
    {
314
        $this->maximumDeliveryDate = $maximumDeliveryDate;
315
        return $this;
316
    }
317
}
318