NumberTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 25
loc 25
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B validateNumber() 14 14 5
addError() 1 1 ?

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