FloatValidation   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 14
lcom 0
cbo 0
dl 0
loc 136
rs 10
c 2
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A isFloat() 0 4 1
A isNotZero() 0 6 1
A isPositiveOrZero() 0 6 1
A isPositive() 0 6 1
A isNegativeOrZero() 0 6 1
A isNegative() 0 6 1
B isBetween() 0 16 5
A isOdd() 0 6 1
A isEven() 0 6 1
A isMultiple() 0 7 1
1
<?php
2
/**
3
 * Author: Nil Portugués Calderó <[email protected]>
4
 * Date: 9/16/14
5
 * Time: 10:19 PM
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace NilPortugues\Validator\Validation\Float;
12
13
/**
14
 * Class FloatValidation
15
 * @package NilPortugues\Validator\Validation\FloatAttribute
16
 */
17
class FloatValidation
18
{
19
    /**
20
     * @param $value
21
     *
22
     * @return bool
23
     */
24
    public static function isFloat($value)
25
    {
26
        return \is_float($value);
27
    }
28
29
    /**
30
     * @param $value
31
     *
32
     * @return bool
33
     */
34
    public static function isNotZero($value)
35
    {
36
        \settype($value, 'float');
37
38
        return 0 != $value;
39
    }
40
41
    /**
42
     * @param double $value
43
     *
44
     * @return bool
45
     */
46
    public static function isPositiveOrZero($value)
47
    {
48
        \settype($value, 'float');
49
50
        return 0 <= $value;
51
    }
52
53
    /**
54
     * @param double $value
55
     *
56
     * @return bool
57
     */
58
    public static function isPositive($value)
59
    {
60
        \settype($value, 'float');
61
62
        return 0 < $value;
63
    }
64
65
    /**
66
     * @param double $value
67
     *
68
     * @return bool
69
     */
70
    public static function isNegativeOrZero($value)
71
    {
72
        \settype($value, 'float');
73
74
        return 0 >= $value;
75
    }
76
77
    /**
78
     * @param double $value
79
     *
80
     * @return bool
81
     */
82
    public static function isNegative($value)
83
    {
84
        \settype($value, 'float');
85
86
        return 0 > $value;
87
    }
88
89
    /**
90
     * @param double $value
91
     * @param double $min
92
     * @param double $max
93
     * @param bool   $inclusive
94
     *
95
     * @throws \InvalidArgumentException
96
     * @return bool
97
     */
98
    public static function isBetween($value, $min, $max, $inclusive = false)
99
    {
100
        \settype($value, 'float');
101
        \settype($min, 'float');
102
        \settype($max, 'float');
103
104
        if ($min > $max) {
105
            throw new \InvalidArgumentException(\sprintf('%s cannot be less than  %s for validation', $min, $max));
106
        }
107
108
        if (false === $inclusive) {
109
            return (($min < $value) && ($value < $max));
110
        }
111
112
        return (($min <= $value) && ($value <= $max));
113
    }
114
115
    /**
116
     * @param float $value
117
     *
118
     * @return bool
119
     */
120
    public static function isOdd($value)
121
    {
122
        \settype($value, 'int');
123
124
        return 1 == ($value % 2);
125
    }
126
127
    /**
128
     * @param float $value
129
     *
130
     * @return bool
131
     */
132
    public static function isEven($value)
133
    {
134
        \settype($value, 'int');
135
136
        return 0 == ($value % 2);
137
    }
138
139
    /**
140
     * @param float $value
141
     * @param float $multiple
142
     *
143
     * @return bool
144
     */
145
    public static function isMultiple($value, $multiple)
146
    {
147
        \settype($value, 'float');
148
        \settype($multiple, 'float');
149
150
        return (float) 0 == \fmod($value, $multiple);
151
    }
152
}
153