hsb   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A to_rgb() 0 16 2
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 hsb implements \projectcleverweb\color\interfaces\converter {
6
	use \projectcleverweb\color\traits\converter;
7
	
8
	protected static $valid_keys = array(
9
		'h',
10
		's',
11
		'b'
12
	);
13
	
14
	protected static $default_value = array(
15
		'h' => 0,
16
		's' => 0,
17
		'b' => 0
18
	);
19
	
20
	public static function to_rgb($input) :array {
21
		$hsb = static::_validate_array_input($input);
22
		if ($hsb['b'] == 0) {
23
			return ['r' => 0, 'g' => 0, 'b' => 0];
24
		}
25
		$hsb['h'] /= 60;
26
		$hsb['s'] /= 100;
27
		$hsb['b'] /= 100;
28
		$i         = floor($hsb['h']);
29
		$f         = $hsb['h'] - $i;
30
		$p         = $hsb['b'] * (1 - $hsb['s']);
31
		$q         = $hsb['b'] * (1 - ($hsb['s'] * $f));
32
		$t         = $hsb['b'] * (1 - ($hsb['s'] * (1 - $f)));
33
		$calc      = [[$hsb['b'], $t, $p],[$q, $hsb['b'], $p],[$p, $hsb['b'], $t],[$p, $q, $hsb['b']],[$t, $p, $hsb['b']],[$hsb['b'], $p, $q]];
34
		return ['r' => $calc[$i][0] * 255, 'g' => $calc[$i][1] * 255, 'b' => $calc[$i][2] * 255];
35
	}
36
	
37
	public static function to_hex($input) :string {
38
		return rgb::to_hex(static::to_rgb($input));
39
	}
40
	
41
	public static function to_cmyk($input) :array {
42
		return rgb::to_cmyk(static::to_rgb($input));
43
	}
44
	
45
	public static function to_hsl($input) :array {
46
		return rgb::to_hsl(static::to_rgb($input));
47
	}
48
	
49
	public static function to_hsb($input) :array {
50
		return static::_validate_array_input($input);
51
	}
52
}
53