Passed
Push — master ( 2e5515...2d6133 )
by Nicholas
02:21
created

cmyk   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A to_rgb() 0 15 1
A to_hex() 0 3 1
A to_cmyk() 0 3 1
A to_hsl() 0 3 1
A to_hsb() 0 3 1
1
<?php
2
3
namespace projectcleverweb\color\convert;
4
5
class cmyk implements \projectcleverweb\color\interfaces\converter {
6
	use \projectcleverweb\color\traits\convert\meta;
7
	
8
	protected static $valid_keys = array(
9
		'c',
10
		'm',
11
		'y',
12
		'k'
13
	);
14
	
15
	protected static $default_value = array(
16
		'c' => 0,
17
		'm' => 0,
18
		'y' => 0,
19
		'k' => 0
20
	);
21
	
22
	public static function to_rgb($input) :array {
23
		$cmyk       = static::_validate_array_input($input);
24
		$cmyk['c'] /= 100;
25
		$cmyk['m'] /= 100;
26
		$cmyk['y'] /= 100;
27
		$cmyk['k'] /= 100;
28
		$r  = 1 - min(1, $cmyk['c'] * (1 - $cmyk['k']) + $cmyk['k']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 2 spaces

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...
29
		$g  = 1 - min(1, $cmyk['m'] * (1 - $cmyk['k']) + $cmyk['k']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 2 spaces

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...
30
		$b  = 1 - min(1, $cmyk['y'] * (1 - $cmyk['k']) + $cmyk['k']);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 2 spaces

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...
31
		return [
32
			'r' => round($r * 255),
33
			'g' => round($g * 255),
34
			'b' => round($b * 255)
35
		];
36
	}
37
	
38
	public static function to_hex($input) :string {
39
		return rgb::to_hex(static::to_rgb($input));
40
	}
41
	
42
	public static function to_cmyk($input) :array {
43
		return static::_validate_array_input($input);
44
	}
45
	
46
	public static function to_hsl($input) :array {
47
		return rgb::to_hsl(static::to_rgb($input));
48
	}
49
	
50
	public static function to_hsb($input) :array {
51
		return rgb::to_hsb(static::to_rgb($input));
52
	}
53
}
54