Completed
Push — master ( 25512e...e66e4c )
by Matt
02:57
created

ExclusiveMinimum::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 4
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace League\JsonGuard\Constraint\DraftFour;
4
5
use League\JsonGuard\Assert;
6
use League\JsonGuard\ConstraintInterface;
7
use League\JsonGuard\Validator;
8
use function League\JsonGuard\error;
9
10 View Code Duplication
final class ExclusiveMinimum implements ConstraintInterface
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...
11
{
12
    const KEYWORD = 'exclusiveMinimum';
13
14
    /**
15
     * @var int|null
16
     */
17
    private $precision;
18
19
    /**
20
     * @param int|null $precision
21
     */
22 6
    public function __construct($precision = 10)
23
    {
24 6
        $this->precision = $precision;
25 6
    }
26
27
    /**
28
     * @param mixed     $value
29
     * @param mixed     $parameter
30
     * @param Validator $validator
31
     *
32
     * @return \League\JsonGuard\ValidationError|null
33
     */
34 6
    public function validate($value, $parameter, Validator $validator)
35
    {
36 6
        Assert::type($parameter, 'boolean', self::KEYWORD, $validator->getSchemaPath());
37 6
        Assert::hasProperty($validator->getSchema(), 'minimum', self::KEYWORD, $validator->getSchemaPath());
38
39 6
        if ($parameter !== true) {
40
            return null;
41
        }
42
43 6
        if (!is_numeric($value) || bccomp($value, $validator->getSchema()->minimum, $this->precision) === 1) {
44 4
            return null;
45
        }
46
47 4
        return error('The number must be greater than {parameter}.', $validator);
48
    }
49
}
50