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

Firmware   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 21.74 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 10
loc 46
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setBuild() 0 4 1
A setVersion() 10 10 3
A __construct() 0 5 1
A getBuild() 0 4 1
A getVersion() 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;
4
5
use DaveRandom\LibLifxLan\Exceptions\InvalidValueException;
6
use const DaveRandom\LibLifxLan\UINT32_MAX;
7
use const DaveRandom\LibLifxLan\UINT32_MIN;
8
use function DaveRandom\LibLifxLan\datetimeinterface_to_datetimeimmutable;
9
10
abstract class Firmware
11
{
12
    private $build;
13
    private $version;
14
15
    private function setBuild(\DateTimeImmutable $build): void
16
    {
17
        $this->build = $build;
18
    }
19
20
    /**
21
     * @param int $version
22
     * @throws InvalidValueException
23
     */
24 View Code Duplication
    private function setVersion(int $version): 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...
25
    {
26
        if ($version < UINT32_MIN || $version > UINT32_MAX) {
27
            throw new InvalidValueException(
28
                "Firmware version {$version} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
29
            );
30
        }
31
32
        $this->version = $version;
33
    }
34
35
    /**
36
     * @param \DateTimeInterface $build
37
     * @param int $version
38
     * @throws InvalidValueException
39
     */
40
    protected function __construct(\DateTimeInterface $build, int $version)
41
    {
42
        $this->setBuild(datetimeinterface_to_datetimeimmutable($build));
43
        $this->setVersion($version);
44
    }
45
46
    public function getBuild(): \DateTimeImmutable
47
    {
48
        return $this->build;
49
    }
50
51
    public function getVersion(): int
52
    {
53
        return $this->version;
54
    }
55
}
56