1 | <?php |
||
6 | class regulate { |
||
7 | |||
8 | /** |
||
9 | * Forces a float to be within the range of 0 and 100. |
||
10 | * |
||
11 | * @param float &$value The value to modify |
||
12 | * @return void |
||
13 | */ |
||
14 | 2 | public static function percent(float &$value) { |
|
17 | |||
18 | /** |
||
19 | * Forces a float to be within the range of 0 and 255. |
||
20 | * |
||
21 | * @param float &$value The value to modify |
||
22 | * @return void |
||
23 | */ |
||
24 | 2 | public static function rgb(int &$value) { |
|
27 | |||
28 | /** |
||
29 | * Forces and RGB array to have specific offsets, and max values. |
||
30 | * |
||
31 | * @param array &$rgb_array The RGB array to modify |
||
32 | * @return void |
||
33 | */ |
||
34 | 1 | public static function rgb_array(array &$rgb_array) { |
|
40 | |||
41 | /** |
||
42 | * Forces a float to be within the range of 0 and 100 or if the offset is |
||
43 | * 'h' 0 and 359. |
||
44 | * |
||
45 | * @param float &$value The value to modify |
||
46 | * @param string $offset The offset that is being modified |
||
47 | * @return void |
||
48 | */ |
||
49 | 1 | public static function hsl(float &$value, string $offset) { |
|
56 | |||
57 | /** |
||
58 | * Forces and HSL array to have specific offsets, and max values. |
||
59 | * |
||
60 | * @param array &$hsl_array The HSL array to modify |
||
61 | * @return void |
||
62 | */ |
||
63 | public static function hsl_array(array &$hsl_array) { |
||
69 | |||
70 | /** |
||
71 | * Forces a float to be within the range of 0 and 100. |
||
72 | * |
||
73 | * @param float &$value The value to modify |
||
74 | * @return void |
||
75 | */ |
||
76 | public static function cmyk(float &$value) { |
||
79 | |||
80 | |||
81 | /** |
||
82 | * Forces a float to be within the range of 0 and 100. |
||
83 | * |
||
84 | * @param float &$value The value to modify |
||
85 | * @return void |
||
86 | */ |
||
87 | public static function alpha(float &$value) { |
||
90 | |||
91 | /** |
||
92 | * Forces and CMYK array to have specific offsets, and max values. |
||
93 | * |
||
94 | * @param array &$cmyk_array The CMYK array to modify |
||
95 | * @return void |
||
96 | */ |
||
97 | public static function cmyk_array(array &$cmyk_array) { |
||
104 | |||
105 | /** |
||
106 | * Forces hexadecimal strings to be valid, without a "#", and not to be |
||
107 | * shorthand. |
||
108 | * |
||
109 | * @param string &$color The color string to modify |
||
110 | * @return void |
||
111 | */ |
||
112 | public static function hex(string &$color) { |
||
117 | |||
118 | /** |
||
119 | * Forces hexadecimal integers to be within the range of 0x0 and 0xFFFFFF. |
||
120 | * |
||
121 | * @param int &$value The value to modify |
||
122 | * @return void |
||
123 | */ |
||
124 | public static function hex_int(int &$value) { |
||
127 | |||
128 | /** |
||
129 | * Strips the hash mark (#) off the beginning of a sting if it has one. |
||
130 | * |
||
131 | * @param string &$hex The hex string |
||
132 | * @return void |
||
133 | */ |
||
134 | public static function _strip_hash(string &$hex) { |
||
139 | |||
140 | /** |
||
141 | * Expand a hex strings in short notation (e.g. 000 => 000000) |
||
142 | * |
||
143 | * @param string &$hex_str The hex string to modify |
||
144 | * @return void |
||
145 | */ |
||
146 | public static function _expand_shorthand(string &$hex_str) { |
||
154 | |||
155 | /** |
||
156 | * Verify that the hex string is actually a hex string. If not force it to |
||
157 | * '000000' |
||
158 | * |
||
159 | * @param string &$hex_str The hex string to modify |
||
160 | * @return void |
||
161 | */ |
||
162 | public static function _validate_hex_str(string &$hex_str) { |
||
173 | |||
174 | /** |
||
175 | * Force an array to have specific lower-case keys. If the array is an indexed |
||
176 | * array and the keys are provided, convert it to an associative array. |
||
177 | * |
||
178 | * @param array &$array The array to be modified |
||
179 | * @return void |
||
180 | */ |
||
181 | 1 | protected static function standardize_array(array &$array, array $keys = []) { |
|
188 | |||
189 | /** |
||
190 | * Absolute and divide any number so it fits between 0 and $max |
||
191 | * |
||
192 | * @param float $number The original number |
||
193 | * @param float $max The maximum value $number should be |
||
194 | * @return float The resulting number as a float |
||
195 | */ |
||
196 | 4 | protected static function max(float $number, float $max) :float { |
|
203 | |||
204 | /** |
||
205 | * Simple dividing method to handle division by 0 |
||
206 | * |
||
207 | * @param float $number The number to divide |
||
208 | * @param float $divisor The number to divide by |
||
209 | * @return float The result |
||
210 | */ |
||
211 | 1 | public static function div(float $number, float $divisor) :float { |
|
217 | } |
||
218 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.