Completed
Push — master ( 699f98...edb5e2 )
by Nicholas
03:56
created

hsl::offsetSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 6
1
<?php
2
3
4
namespace projectcleverweb\color;
5
6
7
class hsl implements \ArrayAccess {
8
	
9
	private $hsl;
10
	protected $accuracy;
11
	
12
	public function __construct(array $rgb_array, int $accuracy = 3) {
13
		$this->accuracy = $accuracy;
14
		$this->hsl      = generate::rgb_to_hsl($rgb_array['r'], $rgb_array['g'], $rgb_array['b'], $this->accuracy);
15
	}
16
	
17
	public function offsetExists($offset) :bool {
18
		return isset($this->hsl[$offset]);
19
	}
20
	
21
	public function offsetGet($offset) {
22
		if ($this->offsetExists($offset)) {
23
			return $this->hsl[$offset];
24
		}
25
		trigger_error(sprintf('Offset "%s" does not exist', $offset));
26
	}
27
	
28
	public function offsetSet($offset, $value) {
29
		if ($this->offsetExists($offset)) {
30
			return $this->hsl[$offset] = (float) $value;
31
		}
32
		trigger_error(sprintf('Offset "%s" cannot be set', $offset));
33
	}
34
	
35
	public function offsetUnset($offset) {
36
		if ($this->offsetExists($offset)) {
37
			return $this->hsl[$offset] = $value;
0 ignored issues
show
Bug introduced by
The variable $value does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
38
		}
39
	}
40
}
41
42
43