NumberTrait::validateNumber()   B
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 5

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 5
nc 4
nop 3
dl 14
loc 14
rs 8.8571
c 0
b 0
f 0
1
<?php namespace CMPayments\SchemaValidator\Validators;
2
3
use CMPayments\SchemaValidator\Exceptions\ValidateException;
4
5
/**
6
 * Class NumberTrait
7
 *
8
 * @package CMPayments\SchemaValidator\Validators
9
 * @Author  Boy Wijnmaalen <[email protected]>
10
 */
11 View Code Duplication
trait NumberTrait
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...
12
{
13
    public function validateNumber($data, $schema, $path)
14
    {
15
        // check for minimum property
16
        if (isset($schema->minimum) && ($data < $schema->minimum)) {
17
18
            $this->addError(ValidateException::ERROR_USER_NUMBER_MINIMUM_CHECK, [$path, $schema->minimum, $data]);
19
        }
20
21
        // check for maximum property
22
        if (isset($schema->maximum) && ($data > $schema->maximum)) {
23
24
            $this->addError(ValidateException::ERROR_USER_NUMBER_MAXIMUM_CHECK, [$path, $schema->maximum, $data]);
25
        }
26
    }
27
28
    /**
29
     * @param int   $code
30
     * @param array $args
31
     *
32
     * @return mixed
33
     */
34
    abstract public function addError($code, array $args = []);
35
}
36