hsl   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 91
Duplicated Lines 21.98 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 20
loc 91
rs 10
c 0
b 0
f 0
ccs 26
cts 26
cp 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 3 1
A offsetExists() 0 3 1
A offsetGet() 10 10 2
A offsetSet() 10 10 2
A offsetUnset() 0 5 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * The HSL Data Class
4
 * ==================
5
 * Contains a color as an HSL array
6
 */
7
8
namespace projectcleverweb\color;
9
10
/**
11
 * The HSL Data Class
12
 * ==================
13
 * Contains a color as an HSL array
14
 */
15
class hsl implements \ArrayAccess {
16
	
17
	/**
18
	 * The HSL data
19
	 * @var array
20
	 */
21
	private $hsl;
22
	
23
	/**
24
	 * The amount of accuracy to use when calculating HSL
25
	 * @var int
26
	 */
27
	protected $accuracy;
28
	
29
	/**
30
	 * Import a color as an HSL value
31
	 * 
32
	 * @param array $rgb_array RGB color array to import
33
	 * @param int   $accuracy  The amount of accuracy to use when calculating HSL
34
	 */
35 13
	public function __construct(array $rgb_array, int $accuracy = 3) {
36 13
		$this->accuracy = $accuracy;
37 13
		$this->hsl      = convert\rgb::to_hsl($rgb_array);
38 13
	}
39
	
40
	/**
41
	 * Shortcut for return the HSL array
42
	 * 
43
	 * @return array The HSL array
44
	 */
45 3
	public function __invoke() {
46 3
		return $this->hsl;
47
	}
48
	
49
	/**
50
	 * Check if offset exists in data array
51
	 * 
52
	 * @param  string $offset The offset to check
53
	 * @return bool           TRUE if the offset exist, FALSE otherwise
54
	 */
55 4
	public function offsetExists($offset) :bool {
56 4
		return isset($this->hsl[$offset]);
57
	}
58
	
59
	/**
60
	 * Get an offset if it exists
61
	 * 
62
	 * @param  string $offset The offset to get
63
	 * @return mixed          The value of the offset
64
	 */
65 2 View Code Duplication
	public function offsetGet($offset) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66 2
		if ($this->offsetExists($offset)) {
67 1
			return $this->hsl[$offset];
68
		}
69 1
		return error::trigger(error::INVALID_ARGUMENT, sprintf(
70 1
			'The offset "%s" does not exist in %s',
71 1
			(string) $offset,
72 1
			__CLASS__
73
		));
74
	}
75
	
76
	/**
77
	 * Set a value in the data array
78
	 * 
79
	 * @param  string $offset The offset to set
80
	 * @param  mixed  $value  The value to set it to
81
	 * @return mixed          The result
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use double|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
82
	 */
83 2 View Code Duplication
	public function offsetSet($offset, $value) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84 2
		if ($this->offsetExists($offset)) {
85 1
			return $this->hsl[$offset] = (float) $value;
86
		}
87 1
		return error::trigger(error::INVALID_ARGUMENT, sprintf(
88 1
			'The offset "%s" cannot be set in %s',
89 1
			(string) $offset,
90 1
			__CLASS__
91
		));
92
	}
93
	
94
	/**
95
	 * Reset an offset to 0
96
	 * 
97
	 * @param  string $offset The offset to unset
98
	 * @return mixed          The result
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use double|null.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
99
	 */
100 1
	public function offsetUnset($offset) {
101 1
		if ($this->offsetExists($offset)) {
102 1
			return $this->hsl[$offset] = 0.0;
103
		}
104 1
	}
105
}
106