Code Duplication    Length = 74-75 lines in 2 locations

src/Rule/AboveRule.php 1 location

@@ 7-81 (lines=75) @@
4
/**
5
 * a > x
6
 */
7
class AboveRule extends AbstractAtomicRule
8
{
9
    /** @var string operator */
10
    const operator = '>';
11
12
    /** @var scalar $minimum */
13
    protected $minimum;
14
15
    /**
16
     * @param string $field The field to apply the rule on.
17
     * @param array  $value The value the field can above to.
18
     */
19
    public function __construct( $field, $minimum )
20
    {
21
        if (   ! is_scalar($minimum)
22
            && ! $minimum instanceof \DateTimeInterface
23
            && null !== $minimum
24
        ) {
25
            throw new \InvalidArgumentException(
26
                "Minimum parameter must be a scalar or null "
27
                ."or implements DateTimeInterface instead of: "
28
                .var_export($minimum, true)
29
            );
30
        }
31
32
        $this->field   = $field;
33
        $this->minimum = $minimum;
34
    }
35
36
    /**
37
     * @deprecated getLowerLimit
38
     */
39
    public function getMinimum()
40
    {
41
        return $this->minimum;
42
    }
43
44
    /**
45
     */
46
    public function getLowerLimit()
47
    {
48
        return $this->minimum;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function getValues()
55
    {
56
        return $this->getMinimum();
57
    }
58
59
    /**
60
     * Checks if the rule do not expect the value to be above infinity.
61
     *
62
     * @return bool
63
     */
64
    public function hasSolution(array $simplification_options=[])
65
    {
66
        // if minimum is null, the rule is equivalent to true
67
        if (is_numeric( $this->minimum )) {
68
            if (is_nan( $this->minimum )) {
69
                return false;
70
            }
71
72
            if (is_infinite( $this->minimum ) && $this->minimum > 0) {
73
                return false;
74
            }
75
        }
76
77
        return true;
78
    }
79
80
    /**/
81
}
82

src/Rule/BelowRule.php 1 location

@@ 7-80 (lines=74) @@
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=[])
42
    {
43
        // if minimum is null, the rule is equivalent to true
44
        if (is_numeric( $this->maximum )) {
45
            if (is_nan( $this->maximum )) {
46
                return false;
47
            }
48
49
            if (is_infinite( $this->maximum ) && $this->maximum < 0) {
50
                return false;
51
            }
52
        }
53
54
        return true;
55
    }
56
57
    /**
58
     * @deprecated getUpperLimit
59
     */
60
    public function getMaximum()
61
    {
62
        return $this->maximum;
63
    }
64
65
    /**
66
     */
67
    public function getUpperLimit()
68
    {
69
        return $this->maximum;
70
    }
71
72
    /**
73
     */
74
    public function getValues()
75
    {
76
        return $this->getMaximum();
77
    }
78
79
    /**/
80
}
81