BelowRule::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 2
nop 2
dl 16
loc 16
ccs 11
cts 11
cp 1
crap 4
rs 9.7333
c 0
b 0
f 0
1
<?php
2
namespace JClaveau\LogicalFilter\Rule;
3
4
/**
5
 * a < x
6
 */
7 View Code Duplication
class BelowRule extends AbstractAtomicRule
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
    /** @var string operator */
10
    const operator = '<';
11
12
    /** @var scalar $minimum */
13
    protected $maximum;
14
15
    /**
16
     * @param string $field The field to apply the rule on.
17
     * @param array  $value The value the field can below to.
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
18
     */
19 123
    public function __construct( $field, $maximum )
20
    {
21 123
        if (   ! is_scalar($maximum)
22 123
            && ! $maximum instanceof \DateTimeInterface
23 123
            && null !== $maximum
24 123
        ) {
25 1
            throw new \InvalidArgumentException(
26
                 "Maximum parameter must be a scalar or null "
27
                ."or implements DateTimeInterface instead of: "
28 1
                .var_export($maximum, true)
29 1
            );
30
        }
31
32 123
        $this->field   = $field;
33 123
        $this->maximum = $maximum;
34 123
    }
35
36
    /**
37
     * Checks if the rule do not expect the value to be above infinity.
38
     *
39
     * @return bool
40
     */
41 32
    public function hasSolution(array $contextual_options=[])
42
    {
43
        // if minimum is null, the rule is equivalent to true
44 32
        if (is_numeric( $this->maximum )) {
45 24
            if (is_nan( $this->maximum )) {
46 1
                return false;
47
            }
48
49 24
            if (is_infinite( $this->maximum ) && $this->maximum < 0) {
50 1
                return false;
51
            }
52 24
        }
53
54 32
        return true;
55
    }
56
57
    /**
58
     * @deprecated getUpperLimit
59
     */
60 111
    public function getMaximum()
61
    {
62 111
        return $this->maximum;
63
    }
64
65
    /**
66
     */
67 36
    public function getUpperLimit()
68
    {
69 36
        return $this->maximum;
70
    }
71
72
    /**
73
     */
74 111
    public function getValues()
75
    {
76 111
        return $this->getMaximum();
0 ignored issues
show
Deprecated Code introduced by
The method JClaveau\LogicalFilter\R...BelowRule::getMaximum() has been deprecated with message: getUpperLimit

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
77
    }
78
79
    /**/
80
}
81