Test Failed
Push — master ( 14bb9e...d96886 )
by Jean
04:16
created

BelowRule::hasSolution()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 6
nc 4
nop 1
dl 0
loc 12
rs 9.6111
c 0
b 0
f 0
1
<?php
2
namespace JClaveau\LogicalFilter\Rule;
3
4
/**
5
 * a < x
6
 */
7
class BelowRule extends AbstractAtomicRule
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.
18
     */
19
    public function __construct( $field, $maximum )
20
    {
21
        if (    !is_scalar($maximum)
22
            &&  !$maximum instanceof \DateTimeInterface
23
            &&  null !== $maximum
24
        ) {
25
            throw new \InvalidArgumentException(
26
                 "Maximum parameter must be a scalar or null "
27
                ."or implements DateTimeInterface instead of: "
28
                .var_export($maximum, true)
29
            );
30
        }
31
32
        $this->field   = $field;
33
        $this->maximum = $maximum;
34
    }
35
36
    /**
37
     * Checks if the rule do not expect the value to be above infinity.
38
     *
39
     * @return bool
40
     */
41
    public function hasSolution(array $contextual_options=[])
0 ignored issues
show
Unused Code introduced by
The parameter $contextual_options is not used and could be removed. ( Ignorable by Annotation )

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

41
    public function hasSolution(/** @scrutinizer ignore-unused */ array $contextual_options=[])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
    {
43
        // if minimum is null, the rule is equivalent to true
44
        if (is_numeric( $this->maximum )) {
45
            if (is_nan( $this->maximum ))
0 ignored issues
show
Bug introduced by
It seems like $this->maximum can also be of type string; however, parameter $val of is_nan() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

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

45
            if (is_nan( /** @scrutinizer ignore-type */ $this->maximum ))
Loading history...
46
                return false;
47
48
            if (is_infinite( $this->maximum ) && $this->maximum < 0)
0 ignored issues
show
Bug introduced by
It seems like $this->maximum can also be of type string; however, parameter $val of is_infinite() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

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

48
            if (is_infinite( /** @scrutinizer ignore-type */ $this->maximum ) && $this->maximum < 0)
Loading history...
49
                return false;
50
        }
51
52
        return true;
53
    }
54
55
    /**
56
     * @deprecated getUpperLimit
57
     */
58
    public function getMaximum()
59
    {
60
        return $this->maximum;
61
    }
62
63
    /**
64
     */
65
    public function getUpperLimit()
66
    {
67
        return $this->maximum;
68
    }
69
70
    /**
71
     */
72
    public function getValues()
73
    {
74
        return $this->getMaximum();
0 ignored issues
show
Deprecated Code introduced by
The function JClaveau\LogicalFilter\R...BelowRule::getMaximum() has been deprecated: getUpperLimit ( Ignorable by Annotation )

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

74
        return /** @scrutinizer ignore-deprecated */ $this->getMaximum();

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

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

Loading history...
75
    }
76
77
    /**/
78
}
79