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

src/Constraint/DraftFour/ExclusiveMinimum.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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