Completed
Push — master ( 5927eb...1e13db )
by
unknown
04:04
created

Min   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 62
loc 62
ccs 28
cts 28
cp 1
rs 10
c 1
b 0
f 0
wmc 9
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 8 8 3
A validateMin() 13 13 3
A validateExclusiveMin() 19 19 3

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\Constraints;
4
5
use League\JsonGuard;
6
use League\JsonGuard\ErrorCode;
7
use League\JsonGuard\ValidationError;
8
9 View Code Duplication
class Min implements ParentSchemaAwarePropertyConstraint
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...
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14 12
    public static function validate($value, $schema, $parameter, $pointer = null)
15
    {
16 12
        if (isset($schema->exclusiveMinimum) && $schema->exclusiveMinimum === true) {
17 4
            return self::validateExclusiveMin($value, $parameter, $pointer);
18
        }
19
20 10
        return self::validateMin($value, $parameter, $pointer);
21
    }
22
23
    /**
24
     * @param mixed       $value
25
     * @param mixed       $parameter
26
     * @param string|null $pointer
27
     *
28
     * @return \League\JsonGuard\ValidationError|null
29
     */
30 10
    public static function validateMin($value, $parameter, $pointer = null)
31
    {
32 10
        if (!is_numeric($value) || $value >= $parameter) {
33 10
            return null;
34
        }
35
36 8
        $message = sprintf(
37 8
            'Number "%s" is not at least "%d"',
38 8
            JsonGuard\asString($value),
39 8
            JsonGuard\asString($parameter)
40 8
        );
41 8
        return new ValidationError($message, ErrorCode::INVALID_MIN, $value, $pointer, ['min' => $parameter]);
42
    }
43
44
    /**
45
     * @param mixed       $value
46
     * @param mixed       $parameter
47
     * @param string|null $pointer
48
     *
49
     * @return \League\JsonGuard\ValidationError|null
50
     */
51 4
    public static function validateExclusiveMin($value, $parameter, $pointer = null)
52
    {
53 4
        if (!is_numeric($value) || $value > $parameter) {
54 4
            return null;
55
        }
56
57 2
        $message = sprintf(
58 2
            'Number "%s" is not at least greater than "%d"',
59 2
            JsonGuard\asString($value),
60 2
            JsonGuard\asString($parameter)
61 2
        );
62 2
        return new ValidationError(
63 2
            $message,
64 2
            ErrorCode::INVALID_EXCLUSIVE_MIN,
65 2
            $value,
66 2
            $pointer,
67 2
            ['exclusive_min' => $parameter]
68 2
        );
69
    }
70
}
71