Test Setup Failed
Push — test ( 610d2f...d11afe )
by Jonathan
03:32
created

ColorObject::hueToRgb()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 15
Code Lines 9

Duplication

Lines 6
Ratio 40 %

Importance

Changes 0
Metric Value
cc 6
eloc 9
nc 16
nop 3
dl 6
loc 15
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Kint\Object;
4
5
use InvalidArgumentException;
6
use LogicException;
7
8
class ColorObject extends BlobObject
0 ignored issues
show
Coding Style introduced by
The property $color_map is not named in camelCase.

This check marks property names that have not been 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 string becomes databaseConnectionString.

Loading history...
9
{
10
    public static $color_map = array(
0 ignored issues
show
Coding Style introduced by
$color_map does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
11
        'aliceblue' => 'f0f8ff',
12
        'antiquewhite' => 'faebd7',
13
        'aqua' => '00ffff',
14
        'aquamarine' => '7fffd4',
15
        'azure' => 'f0ffff',
16
        'beige' => 'f5f5dc',
17
        'bisque' => 'ffe4c4',
18
        'black' => '000000',
19
        'blanchedalmond' => 'ffebcd',
20
        'blue' => '0000ff',
21
        'blueviolet' => '8a2be2',
22
        'brown' => 'a52a2a',
23
        'burlywood' => 'deb887',
24
        'cadetblue' => '5f9ea0',
25
        'chartreuse' => '7fff00',
26
        'chocolate' => 'd2691e',
27
        'coral' => 'ff7f50',
28
        'cornflowerblue' => '6495ed',
29
        'cornsilk' => 'fff8dc',
30
        'crimson' => 'dc143c',
31
        'cyan' => '00ffff',
32
        'darkblue' => '00008b',
33
        'darkcyan' => '008b8b',
34
        'darkgoldenrod' => 'b8860b',
35
        'darkgray' => 'a9a9a9',
36
        'darkgreen' => '006400',
37
        'darkgrey' => 'a9a9a9',
38
        'darkkhaki' => 'bdb76b',
39
        'darkmagenta' => '8b008b',
40
        'darkolivegreen' => '556b2f',
41
        'darkorange' => 'ff8c00',
42
        'darkorchid' => '9932cc',
43
        'darkred' => '8b0000',
44
        'darksalmon' => 'e9967a',
45
        'darkseagreen' => '8fbc8f',
46
        'darkslateblue' => '483d8b',
47
        'darkslategray' => '2f4f4f',
48
        'darkslategrey' => '2f4f4f',
49
        'darkturquoise' => '00ced1',
50
        'darkviolet' => '9400d3',
51
        'deeppink' => 'ff1493',
52
        'deepskyblue' => '00bfff',
53
        'dimgray' => '696969',
54
        'dimgrey' => '696969',
55
        'dodgerblue' => '1e90ff',
56
        'firebrick' => 'b22222',
57
        'floralwhite' => 'fffaf0',
58
        'forestgreen' => '228b22',
59
        'fuchsia' => 'ff00ff',
60
        'gainsboro' => 'dcdcdc',
61
        'ghostwhite' => 'f8f8ff',
62
        'gold' => 'ffd700',
63
        'goldenrod' => 'daa520',
64
        'gray' => '808080',
65
        'green' => '008000',
66
        'greenyellow' => 'adff2f',
67
        'grey' => '808080',
68
        'honeydew' => 'f0fff0',
69
        'hotpink' => 'ff69b4',
70
        'indianred' => 'cd5c5c',
71
        'indigo' => '4b0082',
72
        'ivory' => 'fffff0',
73
        'khaki' => 'f0e68c',
74
        'lavender' => 'e6e6fa',
75
        'lavenderblush' => 'fff0f5',
76
        'lawngreen' => '7cfc00',
77
        'lemonchiffon' => 'fffacd',
78
        'lightblue' => 'add8e6',
79
        'lightcoral' => 'f08080',
80
        'lightcyan' => 'e0ffff',
81
        'lightgoldenrodyellow' => 'fafad2',
82
        'lightgray' => 'd3d3d3',
83
        'lightgreen' => '90ee90',
84
        'lightgrey' => 'd3d3d3',
85
        'lightpink' => 'ffb6c1',
86
        'lightsalmon' => 'ffa07a',
87
        'lightseagreen' => '20b2aa',
88
        'lightskyblue' => '87cefa',
89
        'lightslategray' => '778899',
90
        'lightslategrey' => '778899',
91
        'lightsteelblue' => 'b0c4de',
92
        'lightyellow' => 'ffffe0',
93
        'lime' => '00ff00',
94
        'limegreen' => '32cd32',
95
        'linen' => 'faf0e6',
96
        'magenta' => 'ff00ff',
97
        'maroon' => '800000',
98
        'mediumaquamarine' => '66cdaa',
99
        'mediumblue' => '0000cd',
100
        'mediumorchid' => 'ba55d3',
101
        'mediumpurple' => '9370db',
102
        'mediumseagreen' => '3cb371',
103
        'mediumslateblue' => '7b68ee',
104
        'mediumspringgreen' => '00fa9a',
105
        'mediumturquoise' => '48d1cc',
106
        'mediumvioletred' => 'c71585',
107
        'midnightblue' => '191970',
108
        'mintcream' => 'f5fffa',
109
        'mistyrose' => 'ffe4e1',
110
        'moccasin' => 'ffe4b5',
111
        'navajowhite' => 'ffdead',
112
        'navy' => '000080',
113
        'oldlace' => 'fdf5e6',
114
        'olive' => '808000',
115
        'olivedrab' => '6b8e23',
116
        'orange' => 'ffa500',
117
        'orangered' => 'ff4500',
118
        'orchid' => 'da70d6',
119
        'palegoldenrod' => 'eee8aa',
120
        'palegreen' => '98fb98',
121
        'paleturquoise' => 'afeeee',
122
        'palevioletred' => 'db7093',
123
        'papayawhip' => 'ffefd5',
124
        'peachpuff' => 'ffdab9',
125
        'peru' => 'cd853f',
126
        'pink' => 'ffc0cb',
127
        'plum' => 'dda0dd',
128
        'powderblue' => 'b0e0e6',
129
        'purple' => '800080',
130
        'rebeccapurple' => '663399',
131
        'red' => 'ff0000',
132
        'rosybrown' => 'bc8f8f',
133
        'royalblue' => '4169e1',
134
        'saddlebrown' => '8b4513',
135
        'salmon' => 'fa8072',
136
        'sandybrown' => 'f4a460',
137
        'seagreen' => '2e8b57',
138
        'seashell' => 'fff5ee',
139
        'sienna' => 'a0522d',
140
        'silver' => 'c0c0c0',
141
        'skyblue' => '87ceeb',
142
        'slateblue' => '6a5acd',
143
        'slategray' => '708090',
144
        'slategrey' => '708090',
145
        'snow' => 'fffafa',
146
        'springgreen' => '00ff7f',
147
        'steelblue' => '4682b4',
148
        'tan' => 'd2b48c',
149
        'teal' => '008080',
150
        'thistle' => 'd8bfd8',
151
        'tomato' => 'ff6347',
152
        'turquoise' => '40e0d0',
153
        'violet' => 'ee82ee',
154
        'wheat' => 'f5deb3',
155
        'white' => 'ffffff',
156
        'whitesmoke' => 'f5f5f5',
157
        'yellow' => 'ffff00',
158
        'yellowgreen' => '9acd32',
159
    );
160
161
    public $hints = array('color');
162
    public $color = null;
163
164
    public function __construct($color)
165
    {
166
        parent::__construct();
167
168
        $this->color = $color;
169
    }
170
171
    /**
172
     * Turns HSL color to RGB. Black magic.
173
     *
174
     * @param float $h Hue
175
     * @param float $s Saturation
176
     * @param float $l Lightness
177
     *
178
     * @return array RGB array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use double[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
179
     */
180
    public static function hslToRgb($h, $s, $l)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $h. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $s. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $l. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
181
    {
182
        if (min($h, $s, $l) < 0) {
183
            throw new InvalidArgumentException('The parameters for hslToRgb should be no less than 0');
184
        } elseif ($h > 360 || max($s, $l) > 100) {
185
            throw new InvalidArgumentException('The parameters for hslToRgb should be no more than 360, 100, and 100 respectively');
186
        }
187
188
        $h /= 360;
189
        $s /= 100;
190
        $l /= 100;
191
192
        $m2 = ($l <= 0.5) ? $l * ($s + 1) : $l + $s - $l * $s;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m2. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
193
        $m1 = $l * 2 - $m2;
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m1. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
194
195
        $out = array(
196
            round(self::hueToRgb($m1, $m2, $h + 1 / 3) * 255),
197
            round(self::hueToRgb($m1, $m2, $h) * 255),
198
            round(self::hueToRgb($m1, $m2, $h - 1 / 3) * 255),
199
        );
200
201
        if (max($out) > 255) {
202
            throw new LogicException('hslToRbg return value should not contain values above 255');
203
        } else {
204
            return $out;
205
        }
206
    }
207
208
    /**
209
     * Helper function for hslToRgb. Even blacker magic.
210
     *
211
     * @return float Color value
212
     */
213
    private static function hueToRgb($m1, $m2, $hue)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m1. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $m2. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
214
    {
215
        $hue = ($hue < 0) ? $hue + 1 : (($hue > 1) ? $hue - 1 : $hue);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $hue. This often makes code more readable.
Loading history...
216 View Code Duplication
        if ($hue * 6 < 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
217
            return $m1 + ($m2 - $m1) * $hue * 6;
218
        }
219
        if ($hue * 2 < 1) {
220
            return $m2;
221
        }
222 View Code Duplication
        if ($hue * 3 < 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
223
            return $m1 + ($m2 - $m1) * (0.66666 - $hue) * 6;
224
        }
225
226
        return $m1;
227
    }
228
229
    /**
230
     * Converts RGB to HSL. Color inversion of previous black magic is white magic?
231
     *
232
     * @param float $red   Red
233
     * @param float $green Green
234
     * @param float $blue  Blue
235
     *
236
     * @return array HSL array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<integer|double>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
237
     */
238
    public static function rgbToHsl($red, $green, $blue)
239
    {
240
        if (min($red, $green, $blue) < 0) {
241
            throw new InvalidArgumentException('The parameters for rgbToHsl should be no less than 0');
242
        } elseif (max($red, $green, $blue) > 255) {
243
            throw new InvalidArgumentException('The parameters for rgbToHsl should be no more than 255');
244
        }
245
246
        $clrMin = min($red, $green, $blue);
247
        $clrMax = max($red, $green, $blue);
248
        $deltaMax = $clrMax - $clrMin;
249
250
        $L = ($clrMax + $clrMin) / 510;
0 ignored issues
show
Coding Style introduced by
$L does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $L. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
251
252
        if (0 == $deltaMax) {
253
            $H = 0;
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $H. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
254
            $S = 0;
0 ignored issues
show
Coding Style introduced by
$S does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility introduced by
Avoid variables with short names like $S. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
255
        } else {
256
            if (0.5 > $L) {
0 ignored issues
show
Coding Style introduced by
$L does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
257
                $S = $deltaMax / ($clrMax + $clrMin);
0 ignored issues
show
Coding Style introduced by
$S does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
258
            } else {
259
                $S = $deltaMax / (510 - $clrMax - $clrMin);
0 ignored issues
show
Coding Style introduced by
$S does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
260
            }
261
262
            if ($clrMax == $red) {
263
                $H = ($green - $blue) / (6.0 * $deltaMax);
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
264
            } elseif ($clrMax == $green) {
265
                $H = 1 / 3 + ($blue - $red) / (6.0 * $deltaMax);
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
266
            } else {
267
                $H = 2 / 3 + ($red - $green) / (6.0 * $deltaMax);
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
268
            }
269
270
            if (0 > $H) {
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
271
                $H += 1;
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
272
            }
273
            if (1 < $H) {
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
274
                $H -= 1;
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
275
            }
276
        }
277
278
        return array(
279
            (round($H * 360) % 360 + 360) % 360,
0 ignored issues
show
Coding Style introduced by
$H does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
280
            round($S * 100),
0 ignored issues
show
Coding Style introduced by
$S does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
281
            round($L * 100),
0 ignored issues
show
Coding Style introduced by
$L does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
282
        );
283
    }
284
}
285