Code Duplication    Length = 24-24 lines in 2 locations

src/Constraint/MaximumConstraint.php 1 location

@@ 19-42 (lines=24) @@
16
/**
17
 * Constraint for the "maximum" and "exclusiveMaximum" keywords.
18
 */
19
class MaximumConstraint extends AbstractRangeConstraint
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function keywords()
25
    {
26
        return ['maximum', 'exclusiveMaximum'];
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function apply($instance, stdClass $schema, Context $context, Walker $walker)
33
    {
34
        if ($schema->exclusiveMaximum === false) {
35
            if ($instance > $schema->maximum) {
36
                $context->addViolation('should be lesser than or equal to %s', [$schema->maximum]);
37
            }
38
        } elseif ($instance >= $schema->maximum) {
39
            $context->addViolation('should be lesser than %s', [$schema->maximum]);
40
        }
41
    }
42
}
43

src/Constraint/MinimumConstraint.php 1 location

@@ 19-42 (lines=24) @@
16
/**
17
 * Constraint for the "minimum" and "exclusiveMinimum" keywords.
18
 */
19
class MinimumConstraint extends AbstractRangeConstraint
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function keywords()
25
    {
26
        return ['minimum', 'exclusiveMinimum'];
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function apply($instance, stdClass $schema, Context $context, Walker $walker)
33
    {
34
        if ($schema->exclusiveMinimum === false) {
35
            if ($instance < $schema->minimum) {
36
                $context->addViolation('should be greater than or equal to %s', [$schema->minimum]);
37
            }
38
        } elseif ($instance <= $schema->minimum) {
39
            $context->addViolation('should be greater than %s', [$schema->minimum]);
40
        }
41
    }
42
}
43