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

Version::setVersion()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 1
dl 10
loc 10
ccs 0
cts 9
cp 0
crap 12
rs 9.4285
c 0
b 0
f 0
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