CouponEligibilityChecker   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 30.43 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 14
loc 46
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A isEligible() 14 14 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
52
    {
53 1
        if (!$this->datesEligibilityChecker->isEligible($coupon)) {
54 1
            return false;
55
        }
56
57 1
        $eligible = $this->rulesEligibilityChecker->isEligible($subject, $coupon->discount);
0 ignored issues
show
Documentation introduced by
The property discount does not exist on object<iBrand\Component\Discount\Models\Coupon>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
58
59 1
        if (!$eligible) {
60 1
            return false;
61
        }
62
63 1
        return $eligible;
64
    }
65
}
66