MaximumConstraint::apply()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 4
nop 4
crap 4
1
<?php
2
3
/*
4
 * This file is part of the JVal package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace JVal\Constraint;
11
12
use JVal\Context;
13
use JVal\Walker;
14
use stdClass;
15
16
/**
17
 * Constraint for the "maximum" and "exclusiveMaximum" keywords.
18
 */
19 View Code Duplication
class MaximumConstraint extends AbstractRangeConstraint
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 395
    public function keywords()
25
    {
26 395
        return ['maximum', 'exclusiveMaximum'];
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 33
    public function apply($instance, stdClass $schema, Context $context, Walker $walker)
33
    {
34 33
        if ($schema->exclusiveMaximum === false) {
35 24
            if ($instance > $schema->maximum) {
36 9
                $context->addViolation('should be lesser than or equal to %s', [$schema->maximum]);
37 9
            }
38 33
        } elseif ($instance >= $schema->maximum) {
39 4
            $context->addViolation('should be lesser than %s', [$schema->maximum]);
40 4
        }
41 33
    }
42
}
43