1 | <?php |
||
5 | class rgb implements \projectcleverweb\color\interfaces\converter { |
||
6 | use \projectcleverweb\color\traits\converter; |
||
7 | |||
8 | protected static $valid_keys = array( |
||
9 | 'r', |
||
10 | 'g', |
||
11 | 'b' |
||
12 | ); |
||
13 | |||
14 | protected static $default_value = array( |
||
15 | 'r' => 0, |
||
16 | 'g' => 0, |
||
17 | 'b' => 0 |
||
18 | ); |
||
19 | |||
20 | public static function to_rgb($input) :array { |
||
23 | |||
24 | public static function to_hex($input) :string { |
||
32 | |||
33 | public static function to_cmyk($input) :array { |
||
48 | |||
49 | public static function to_hsl($input) :array { |
||
50 | $rgb = static::_validate_array_input($input); |
||
51 | $r = $rgb['r'] / 255; |
||
52 | $g = $rgb['g'] / 255; |
||
53 | $b = $rgb['b'] / 255; |
||
54 | $min = min($r, $g, $b); |
||
55 | $max = max($r, $g, $b); |
||
56 | $delta = $max - $min; |
||
57 | $h = 0; |
||
58 | $s = 0; |
||
59 | $l = ($max + $min) / 2; |
||
60 | |||
61 | if ($max != $min) { |
||
62 | $s = $delta / ($max + $min); |
||
63 | if ($l >= 0.5) { |
||
64 | $s = $delta / (2 - $max - $min); |
||
65 | } |
||
66 | static::_rgbhsl_hue($h, $r, $g, $b, $max, $delta); |
||
67 | } |
||
68 | |||
69 | return [ |
||
70 | 'h' => $h * 360, |
||
71 | 's' => $s * 100, |
||
72 | 'l' => $l * 100 |
||
73 | ]; |
||
74 | } |
||
75 | |||
76 | public static function to_hsb($input) :array { |
||
98 | } |
||
99 |
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.