1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace projectcleverweb\color; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
class main implements \Serializable { |
8
|
|
|
|
9
|
|
|
public $color; |
10
|
|
|
|
11
|
|
|
public function __construct($color) { |
12
|
|
|
$this->set($color); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function serialize() :string { |
16
|
|
|
return $this->color->serialize(); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function unserialize($serialized) { |
20
|
|
|
$unserialized = (array) json_decode((string) $serialized); |
21
|
|
|
regulate::rgb_array($unserialized); |
22
|
|
|
$this->set($unserialized, 'rgb'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function set($color, string $type = '') { |
26
|
|
|
if ($color instanceof color) { |
27
|
|
|
$this->color = $color; |
28
|
|
|
} else { |
29
|
|
|
$this->color = new color($color, $type); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function rgb() { |
34
|
|
|
return (array) $this->color->rgb; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function hsl() { |
38
|
|
|
return (array) $this->color->hsl; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function is_dark(int $check_score = 128) :bool { |
42
|
|
|
$rgb = $this->color->rgb; |
43
|
|
|
return check::is_dark($rgb['r'], $rgb['g'], $rgb['b'], $check_score); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function red(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
47
|
|
|
return modify::rgb($this->color, 'red', $adjustment, $as_percentage, $set_absolute); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function green(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
51
|
|
|
return modify::rgb($this->color, 'green', $adjustment, $as_percentage, $set_absolute); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function blue(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
55
|
|
|
return modify::rgb($this->color, 'blue', $adjustment, $as_percentage, $set_absolute); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function hue(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
59
|
|
|
return modify::hsl($this->color, 'hue', $adjustment, $as_percentage, $set_absolute); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function saturation(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
63
|
|
|
return modify::hsl($this->color, 'saturation', $adjustment, $as_percentage, $set_absolute); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function light(float $adjustment, bool $as_percentage = FALSE, bool $set_absolute = TRUE) { |
67
|
|
|
return modify::hsl($this->color, 'light', $adjustment, $as_percentage, $set_absolute); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function get_scheme(string $scheme_name = '') { |
71
|
|
|
if (is_callable(array(__NAMESPACE__.'\\scheme', $scheme_name))) { |
72
|
|
|
$hsl = $this->color->hsl; |
|
|
|
|
73
|
|
|
$scheme = call_user_func_array(array(__NAMESPACE__.'\\scheme', $scheme_name), $hsl['h'], $hsl['s'], $hsl['l']); |
74
|
|
|
foreach ($scheme as &$val) { |
75
|
|
|
$val = generate::hsl_to_rgb($val['h'], $val['s'], $val['l']); |
76
|
|
|
} |
77
|
|
|
return $scheme; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function get_hex_scheme(string $scheme_name = '') { |
|
|
|
|
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.