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

Version   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 79
Duplicated Lines 37.97 %

Coupling/Cohesion

Components 3
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 30
loc 79
ccs 0
cts 45
cp 0
rs 10
c 0
b 0
f 0
wmc 13
lcom 3
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setVendor() 10 10 3
A setProduct() 10 10 3
A setVersion() 10 10 3
A __construct() 0 6 1
A getVendor() 0 4 1
A getProduct() 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
9
final class Version
10
{
11
    private $vendor;
12
    private $product;
13
    private $version;
14
15
    /**
16
     * @param int $vendor
17
     * @throws InvalidValueException
18
     */
19 View Code Duplication
    private function setVendor(int $vendor): 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...
20
    {
21
        if ($vendor < UINT32_MIN || $vendor > UINT32_MAX) {
22
            throw new InvalidValueException(
23
                "Vendor ID {$vendor} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
24
            );
25
        }
26
27
        $this->vendor = $vendor;
28
    }
29
30
    /**
31
     * @param int $product
32
     * @throws InvalidValueException
33
     */
34 View Code Duplication
    private function setProduct(int $product): 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...
35
    {
36
        if ($product < UINT32_MIN || $product > UINT32_MAX) {
37
            throw new InvalidValueException(
38
                "Product ID {$product} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
39
            );
40
        }
41
42
        $this->product = $product;
43
    }
44
45
    /**
46
     * @param int $version
47
     * @throws InvalidValueException
48
     */
49 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...
50
    {
51
        if ($version < UINT32_MIN || $version > UINT32_MAX) {
52
            throw new InvalidValueException(
53
                "Product version {$version} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
54
            );
55
        }
56
57
        $this->version = $version;
58
    }
59
60
    /**
61
     * @param int $vendor
62
     * @param int $product
63
     * @param int $version
64
     * @throws InvalidValueException
65
     */
66
    public function __construct(int $vendor, int $product, int $version)
67
    {
68
        $this->setVendor($vendor);
69
        $this->setProduct($product);
70
        $this->setVersion($version);
71
    }
72
73
    public function getVendor(): int
74
    {
75
        return $this->vendor;
76
    }
77
78
    public function getProduct(): int
79
    {
80
        return $this->product;
81
    }
82
83
    public function getVersion(): int
84
    {
85
        return $this->version;
86
    }
87
}
88