Passed
Pull Request — master (#22)
by Christopher
02:16
created

MinMaxTrait   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 83
Duplicated Lines 19.28 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 13
c 3
b 1
f 0
lcom 1
cbo 0
dl 16
loc 83
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setMaxInclusive() 0 4 1
A setMaxExclusive() 8 8 2
A setMinExclusive() 8 8 2
A setMinInclusive() 0 4 1
A CheckMin() 0 6 2
A CheckMax() 0 6 2
A checkMinMax() 0 9 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
namespace AlgoWeb\xsdTypes\Facets;
3
4
trait MinMaxTrait
5
{
6
    /**
7
     * @Exclude
8
     * @var int|float|\DateTime|\DateInterval Specifies the lower bounds for numeric values (the value must be greater
9
     *                                        than or equal to this value)
10
     */
11
    private $minInclusive = null;
12
    /**
13
     * @Exclude
14
     * @var int|float|\DateTime|\DateInterval Specifies the upper bounds for numeric values (the value must be less
15
     *                                        than or equal to this value)
16
     */
17
    private $maxInclusive = null;
18
19
    /**
20
     * @param int|float|\DateTime|\DateInterval $v Specifies the upper bounds for numeric values (the value must be
21
     *                                             less than this value)
22
     */
23 View Code Duplication
    public function setMaxExclusive($v)
24
    {
25
        if (is_int($v)) {
26
            $this->maxInclusive = $v - 1;
27
        } else {
28
            $this->minInclusive = $v - 0.000001;
29
        }
30
    }
31
32
    /**
33
     * @param int|float|\DateTime|\DateInterval $v Specifies the upper bounds for numeric values
34
     *                                             (the value must be less than or equal to this value)
35
     */
36
    public function setMaxInclusive($v)
37
    {
38
        $this->maxInclusive = $v;
39
    }
40
41
    /**
42
     * @param int|float|\DateTime|\DateInterval $v Specifies the lower bounds for numeric values
43
     *                                             (the value must be greater than this value)
44
     */
45 View Code Duplication
    public function setMinExclusive($v)
46
    {
47
        if (is_int($v)) {
48
            $this->minInclusive = $v + 1;
49
        } else {
50
            $this->minInclusive = $v + 0.000001;
51
        }
52
    }
53
54
    /**
55
     * @param int|float|\DateTime|\DateInterval $v Specifies the lower bounds for numeric values
56
     *                                             (the value must be greater than or equal to this value)
57
     */
58
    public function setMinInclusive($v)
59
    {
60
        $this->minInclusive = $v;
61
    }
62
63
    public function checkMinMax($v)
64
    {
65
        if (null != $this->minInclusive) {
66
            $this->CheckMin($v);
67
        }
68
        if (null != $this->maxInclusive) {
69
            $this->CheckMax($v);
70
        }
71
    }
72
73
    private function CheckMin($v)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
74
    {
75
        if ($v < $this->minInclusive) {
76
            throw new \InvalidArgumentException('Value less than allowed min value ' . __CLASS__);
77
        }
78
    }
79
80
    private function CheckMax($v)
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
81
    {
82
        if ($v > $this->maxInclusive) {
83
            throw new \InvalidArgumentException('Value greater than allowed max value ' . __CLASS__);
84
        }
85
    }
86
}
87