Failed Conditions
Pull Request — experimental/sf (#3236)
by Kentaro
144:19 queued 116:23
created

TaxRule::compareTo()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.2

Importance

Changes 0
Metric Value
cc 5
nc 5
nop 1
dl 0
loc 19
rs 9.3222
c 0
b 0
f 0
ccs 8
cts 10
cp 0.8
crap 5.2
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Entity;
15
16
use Doctrine\ORM\Mapping as ORM;
17
18
/**
19
 * TaxRule
20
 *
21
 * @ORM\Table(name="dtb_tax_rule")
22
 * @ORM\InheritanceType("SINGLE_TABLE")
23
 * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
24
 * @ORM\HasLifecycleCallbacks()
25
 * @ORM\Entity(repositoryClass="Eccube\Repository\TaxRuleRepository")
26
 */
27
class TaxRule extends \Eccube\Entity\AbstractEntity
28
{
29
    /**
30
     * @var integer
31
     */
32
    const DEFAULT_TAX_RULE_ID = 1;
33
34
    /**
35
     * @var integer
36
     */
37
    private $sort_no;
38
39
    /**
40
     * is default
41
     *
42
     * @return bool
43
     */
44 4
    public function isDefaultTaxRule()
45
    {
46 4
        return self::DEFAULT_TAX_RULE_ID === $this->getId();
47
    }
48
49
    /**
50
     * Set sortNo
51
     *
52
     * @param  integer $sortNo
53
     *
54
     * @return TaxRule
55
     */
56 462
    public function setSortNo($sortNo)
57
    {
58 462
        $this->sort_no = $sortNo;
59
60 462
        return $this;
61
    }
62
63
    /**
64
     * Get sortNo
65
     *
66
     * @return integer
67
     */
68 5
    public function getSortNo()
69
    {
70 5
        return $this->sort_no;
71
    }
72
73
    /**
74
     * @var int
75
     *
76
     * @ORM\Column(name="id", type="integer", options={"unsigned":true})
77
     * @ORM\Id
78
     * @ORM\GeneratedValue(strategy="IDENTITY")
79
     */
80
    private $id;
81
82
    /**
83
     * @var string
84
     *
85
     * @ORM\Column(name="tax_rate", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":8})
86
     */
87
    private $tax_rate = 8;
88
89
    /**
90
     * @var string
91
     *
92
     * @ORM\Column(name="tax_adjust", type="decimal", precision=10, scale=0, options={"unsigned":true,"default":0})
93
     */
94
    private $tax_adjust = 0;
95
96
    /**
97
     * @var \DateTime
98
     *
99
     * @ORM\Column(name="apply_date", type="datetimetz")
100
     */
101
    private $apply_date;
102
103
    /**
104
     * @var \DateTime
105
     *
106
     * @ORM\Column(name="create_date", type="datetimetz")
107
     */
108
    private $create_date;
109
110
    /**
111
     * @var \DateTime
112
     *
113
     * @ORM\Column(name="update_date", type="datetimetz")
114
     */
115
    private $update_date;
116
117
    /**
118
     * @var \Eccube\Entity\ProductClass
119
     *
120
     * @ORM\OneToOne(targetEntity="Eccube\Entity\ProductClass", inversedBy="TaxRule")
121
     * @ORM\JoinColumns({
122
     *   @ORM\JoinColumn(name="product_class_id", referencedColumnName="id")
123
     * })
124
     */
125
    private $ProductClass;
126
127
    /**
128
     * @var \Eccube\Entity\Member
129
     *
130
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Member")
131
     * @ORM\JoinColumns({
132
     *   @ORM\JoinColumn(name="creator_id", referencedColumnName="id")
133
     * })
134
     */
135
    private $Creator;
136
137
    /**
138
     * @var \Eccube\Entity\Master\Country
139
     *
140
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Country")
141
     * @ORM\JoinColumns({
142
     *   @ORM\JoinColumn(name="country_id", referencedColumnName="id")
143
     * })
144
     */
145
    private $Country;
146
147
    /**
148
     * @var \Eccube\Entity\Master\Pref
149
     *
150
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Pref")
151
     * @ORM\JoinColumns({
152
     *   @ORM\JoinColumn(name="pref_id", referencedColumnName="id")
153
     * })
154
     */
155
    private $Pref;
156
157
    /**
158
     * @var \Eccube\Entity\Product
159
     *
160
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Product")
161
     * @ORM\JoinColumns({
162
     *   @ORM\JoinColumn(name="product_id", referencedColumnName="id")
163
     * })
164
     */
165
    private $Product;
166
167
    /**
168
     * @var \Eccube\Entity\Master\RoundingType
169
     *
170
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\RoundingType")
171
     * @ORM\JoinColumns({
172
     *   @ORM\JoinColumn(name="rounding_type_id", referencedColumnName="id")
173
     * })
174
     */
175
    private $RoundingType;
176
177
    /**
178
     * Get id.
179
     *
180
     * @return int
181
     */
182 222
    public function getId()
183
    {
184 222
        return $this->id;
185
    }
186
187
    /**
188
     * Set taxRate.
189
     *
190
     * @param string $taxRate
191
     *
192
     * @return TaxRule
193
     */
194 30
    public function setTaxRate($taxRate)
195
    {
196 30
        $this->tax_rate = $taxRate;
197
198 30
        return $this;
199
    }
200
201
    /**
202
     * Get taxRate.
203
     *
204
     * @return string
205
     */
206 466
    public function getTaxRate()
207
    {
208 466
        return $this->tax_rate;
209
    }
210
211
    /**
212
     * Set taxAdjust.
213
     *
214
     * @param string $taxAdjust
215
     *
216
     * @return TaxRule
217
     */
218 29
    public function setTaxAdjust($taxAdjust)
219
    {
220 29
        $this->tax_adjust = $taxAdjust;
221
222 29
        return $this;
223
    }
224
225
    /**
226
     * Get taxAdjust.
227
     *
228
     * @return string
229
     */
230 462
    public function getTaxAdjust()
231
    {
232 462
        return $this->tax_adjust;
233
    }
234
235
    /**
236
     * Set applyDate.
237
     *
238
     * @param \DateTime $applyDate
239
     *
240
     * @return TaxRule
241
     */
242 40
    public function setApplyDate($applyDate)
243
    {
244 40
        $this->apply_date = $applyDate;
245
246 40
        return $this;
247
    }
248
249
    /**
250
     * Get applyDate.
251
     *
252
     * @return \DateTime
253
     */
254 14
    public function getApplyDate()
255
    {
256 14
        return $this->apply_date;
257
    }
258
259
    /**
260
     * Set createDate.
261
     *
262
     * @param \DateTime $createDate
263
     *
264
     * @return TaxRule
265
     */
266 28
    public function setCreateDate($createDate)
267
    {
268 28
        $this->create_date = $createDate;
269
270 28
        return $this;
271
    }
272
273
    /**
274
     * Get createDate.
275
     *
276
     * @return \DateTime
277
     */
278
    public function getCreateDate()
279
    {
280
        return $this->create_date;
281
    }
282
283
    /**
284
     * Set updateDate.
285
     *
286
     * @param \DateTime $updateDate
287
     *
288
     * @return TaxRule
289
     */
290 36
    public function setUpdateDate($updateDate)
291
    {
292 36
        $this->update_date = $updateDate;
293
294 36
        return $this;
295
    }
296
297
    /**
298
     * Get updateDate.
299
     *
300
     * @return \DateTime
301
     */
302
    public function getUpdateDate()
303
    {
304
        return $this->update_date;
305
    }
306
307
    /**
308
     * Set productClass.
309
     *
310
     * @param \Eccube\Entity\ProductClass|null $productClass
311
     *
312
     * @return TaxRule
313
     */
314 16
    public function setProductClass(\Eccube\Entity\ProductClass $productClass = null)
315
    {
316 16
        $this->ProductClass = $productClass;
317
318 16
        return $this;
319
    }
320
321
    /**
322
     * Get productClass.
323
     *
324
     * @return \Eccube\Entity\ProductClass|null
325
     */
326
    public function getProductClass()
327
    {
328
        return $this->ProductClass;
329
    }
330
331
    /**
332
     * Set creator.
333
     *
334
     * @param \Eccube\Entity\Member|null $creator
335
     *
336
     * @return TaxRule
337
     */
338 27
    public function setCreator(\Eccube\Entity\Member $creator = null)
339
    {
340 27
        $this->Creator = $creator;
341
342 27
        return $this;
343
    }
344
345
    /**
346
     * Get creator.
347
     *
348
     * @return \Eccube\Entity\Member|null
349
     */
350
    public function getCreator()
351
    {
352
        return $this->Creator;
353
    }
354
355
    /**
356
     * Set country.
357
     *
358
     * @param \Eccube\Entity\Master\Country|null $country
359
     *
360
     * @return TaxRule
361
     */
362 2
    public function setCountry(\Eccube\Entity\Master\Country $country = null)
363
    {
364 2
        $this->Country = $country;
365
366 2
        return $this;
367
    }
368
369
    /**
370
     * Get country.
371
     *
372
     * @return \Eccube\Entity\Master\Country|null
373
     */
374
    public function getCountry()
375
    {
376
        return $this->Country;
377
    }
378
379
    /**
380
     * Set pref.
381
     *
382
     * @param \Eccube\Entity\Master\Pref|null $pref
383
     *
384
     * @return TaxRule
385
     */
386 1
    public function setPref(\Eccube\Entity\Master\Pref $pref = null)
387
    {
388 1
        $this->Pref = $pref;
389
390 1
        return $this;
391
    }
392
393
    /**
394
     * Get pref.
395
     *
396
     * @return \Eccube\Entity\Master\Pref|null
397
     */
398
    public function getPref()
399
    {
400
        return $this->Pref;
401
    }
402
403
    /**
404
     * Set product.
405
     *
406
     * @param \Eccube\Entity\Product|null $product
407
     *
408
     * @return TaxRule
409
     */
410 18
    public function setProduct(\Eccube\Entity\Product $product = null)
411
    {
412 18
        $this->Product = $product;
413
414 18
        return $this;
415
    }
416
417
    /**
418
     * Get product.
419
     *
420
     * @return \Eccube\Entity\Product|null
421
     */
422
    public function getProduct()
423
    {
424
        return $this->Product;
425
    }
426
427
    /**
428
     * Set calcRule.
429
     *
430
     *
431
     * @return TaxRule
432
     */
433 29
    public function setRoundingType(\Eccube\Entity\Master\RoundingType $RoundingType = null)
434
    {
435 29
        $this->RoundingType = $RoundingType;
436
437 29
        return $this;
438
    }
439
440
    /**
441
     * Get calcRule.
442
     *
443
     * @return \Eccube\Entity\Master\RoundingType|null
444
     */
445 468
    public function getRoundingType()
446
    {
447 468
        return $this->RoundingType;
448
    }
449
450
    /**
451
     * 自分自身と Target を比較し, ソートのための数値を返す.
452
     *
453
     * 以下の順で比較し、
454
     *
455
     * 同一であれば 0
456
     * 自分の方が大きければ正の整数
457
     * 小さければ負の整数を返す.
458
     *
459
     * 1. apply_date
460
     * 2. sort_no
461
     *
462
     * このメソッドは usort() 関数などで使用する.
463
     *
464
     * @param TaxRule $Target 比較対象の TaxRule
465
     *
466
     * @return integer
467
     */
468 8
    public function compareTo(TaxRule $Target)
469
    {
470 8
        if ($this->getApplyDate()->format('YmdHis') == $Target->getApplyDate()->format('YmdHis')) {
471 5
            if ($this->getSortNo() == $Target->getSortNo()) {
472
                return 0;
473
            }
474 5
            if ($this->getSortNo() > $Target->getSortNo()) {
475 4
                return -1;
476
            } else {
477 1
                return 1;
478
            }
479
        } else {
480 3
            if ($this->getApplyDate()->format('YmdHis') > $Target->getApplyDate()->format('YmdHis')) {
481 3
                return -1;
482
            } else {
483
                return 1;
484
            }
485
        }
486
    }
487
}
488