ExclusiveMinimum   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 40
loc 40
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A validate() 15 15 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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