Completed
Push — master ( ba407f...6dbf2d )
by Chris
02:29
created

State   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 14.04 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 8
loc 57
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setColor() 0 4 1
A setPower() 8 8 3
A setLabel() 0 4 1
A __construct() 0 6 1
A getColor() 0 4 1
A getPower() 0 4 1
A getLabel() 0 4 1

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 declare(strict_types=1);
2
3
namespace DaveRandom\LibLifxLan\DataTypes\Light;
4
5
use DaveRandom\LibLifxLan\DataTypes\Label;
6
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException;
7
8
final class State
9
{
10
    private $color;
11
    private $power;
12
    private $label;
13
14
    private function setColor(HsbkColor $color): void
15
    {
16
        $this->color = $color;
17
    }
18
19
    /**
20
     * @param int $power
21
     * @throws InvalidValueException
22
     */
23 View Code Duplication
    private function setPower(int $power): void
1 ignored issue
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...
24
    {
25
        if ($power < 0 || $power > 65535) {
26
            throw new InvalidValueException("Power level {$power} outside allowable range of 0 - 65535");
27
        }
28
29
        $this->power = $power;
30
    }
31
32
    private function setLabel(Label $label): void
33
    {
34
        $this->label = $label;
35
    }
36
37
    /**
38
     * @param HsbkColor $color
39
     * @param int $power
40
     * @param Label $label
41
     * @throws InvalidValueException
42
     */
43
    public function __construct(HsbkColor $color, int $power, Label $label)
44
    {
45
        $this->setColor($color);
46
        $this->setPower($power);
47
        $this->setLabel($label);
48
    }
49
50
    public function getColor(): HsbkColor
51
    {
52
        return $this->color;
53
    }
54
55
    public function getPower(): int
56
    {
57
        return $this->power;
58
    }
59
60
    public function getLabel(): Label
61
    {
62
        return $this->label;
63
    }
64
}
65