|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of ibrand/discount. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) iBrand <https://www.ibrand.cc> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace iBrand\Component\Discount\Checkers; |
|
13
|
|
|
|
|
14
|
|
|
use iBrand\Component\Discount\Contracts\DiscountSubjectContract; |
|
15
|
|
|
use iBrand\Component\Discount\Models\Coupon; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class CouponEligibilityChecker. |
|
19
|
|
|
*/ |
|
20
|
|
|
class CouponEligibilityChecker |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var RulesEligibilityChecker |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $rulesEligibilityChecker; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var DatesEligibilityChecker |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $datesEligibilityChecker; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* CouponEligibilityChecker constructor. |
|
33
|
|
|
* |
|
34
|
|
|
* @param RulesEligibilityChecker $rulesEligibilityChecker |
|
35
|
|
|
* @param DatesEligibilityChecker $datesEligibilityChecker |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function __construct( |
|
38
|
|
|
RulesEligibilityChecker $rulesEligibilityChecker, |
|
39
|
|
|
DatesEligibilityChecker $datesEligibilityChecker |
|
40
|
|
|
) { |
|
41
|
1 |
|
$this->rulesEligibilityChecker = $rulesEligibilityChecker; |
|
42
|
1 |
|
$this->datesEligibilityChecker = $datesEligibilityChecker; |
|
43
|
1 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param DiscountSubjectContract $subject |
|
47
|
|
|
* @param Coupon $coupon |
|
48
|
|
|
* |
|
49
|
|
|
* @return bool |
|
50
|
|
|
*/ |
|
51
|
1 |
View Code Duplication |
public function isEligible(DiscountSubjectContract $subject, Coupon $coupon) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
1 |
|
if (!$this->datesEligibilityChecker->isEligible($coupon)) { |
|
54
|
1 |
|
return false; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
$eligible = $this->rulesEligibilityChecker->isEligible($subject, $coupon->discount); |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
1 |
|
if (!$eligible) { |
|
60
|
1 |
|
return false; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
1 |
|
return $eligible; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.