Completed
Push — master ( eb6f0f...0f89cf )
by Nicholas
05:27
created

main   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 5
dl 0
loc 78
ccs 0
cts 44
cp 0
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A serialize() 0 3 1
A unserialize() 0 5 1
A set() 0 7 2
A rgb() 0 3 1
A hsl() 0 3 1
A is_dark() 0 4 1
A red() 0 3 1
A green() 0 3 1
A blue() 0 3 1
A hue() 0 3 1
A saturation() 0 3 1
A light() 0 3 1
A get_scheme() 0 10 3
A get_hex_scheme() 0 3 1
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;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
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 = '') {
0 ignored issues
show
Unused Code introduced by
The parameter $scheme_name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
		
83
	}
84
}
85