Code Duplication    Length = 10-11 lines in 9 locations

src/DataTypes/Firmware.php 1 location

@@ 24-33 (lines=10) @@
21
     * @param int $version
22
     * @throws InvalidValueException
23
     */
24
    private function setVersion(int $version): void
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

src/DataTypes/Light/ColorTransition.php 1 location

@@ 23-32 (lines=10) @@
20
     * @param int $duration
21
     * @throws InvalidValueException
22
     */
23
    private function setDuration(int $duration): void
24
    {
25
        if ($duration < UINT32_MIN || $duration > UINT32_MAX) {
26
            throw new InvalidValueException(
27
                "Transition duration {$duration} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
28
            );
29
        }
30
31
        $this->duration = $duration;
32
    }
33
34
    /**
35
     * @param HsbkColor $color

src/DataTypes/Light/PowerTransition.php 1 location

@@ 31-40 (lines=10) @@
28
     * @param int $duration
29
     * @throws InvalidValueException
30
     */
31
    private function setDuration(int $duration): void
32
    {
33
        if ($duration < UINT32_MIN || $duration > UINT32_MAX) {
34
            throw new InvalidValueException(
35
                "Transition duration {$duration} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
36
            );
37
        }
38
39
        $this->duration = $duration;
40
    }
41
42
    /**
43
     * @param int $level

src/DataTypes/NetworkInfo.php 2 locations

@@ 19-28 (lines=10) @@
16
     * @param int $tx
17
     * @throws InvalidValueException
18
     */
19
    private function setTx(int $tx): void
20
    {
21
        if ($tx < UINT32_MIN || $tx > UINT32_MAX) {
22
            throw new InvalidValueException(
23
                "Transmitted bytes {$tx} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
24
            );
25
        }
26
27
        $this->tx = $tx;
28
    }
29
30
    /**
31
     * @param int $rx
@@ 34-43 (lines=10) @@
31
     * @param int $rx
32
     * @throws InvalidValueException
33
     */
34
    private function setRx(int $rx): void
35
    {
36
        if ($rx < UINT32_MIN || $rx > UINT32_MAX) {
37
            throw new InvalidValueException(
38
                "Recieved bytes {$rx} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
39
            );
40
        }
41
42
        $this->rx = $rx;
43
    }
44
45
    /**
46
     * @param float $signal

src/DataTypes/Service.php 1 location

@@ 31-41 (lines=11) @@
28
     * @param int $port
29
     * @throws InvalidValueException
30
     */
31
    private function setPort(int $port): void
32
    {
33
        // Protocol spec states this is a uint32 rather than a uint16, so allow any uint32 value at the protocol level
34
        if ($port < UINT32_MIN || $port > UINT32_MAX) {
35
            throw new InvalidValueException(
36
                "Port {$port} outside allowable range of " . UINT32_MIN . " - " . UINT32_MAX
37
            );
38
        }
39
40
        $this->port = $port;
41
    }
42
43
    /**
44
     * @param int $typeId

src/DataTypes/Version.php 3 locations

@@ 19-28 (lines=10) @@
16
     * @param int $vendor
17
     * @throws InvalidValueException
18
     */
19
    private function setVendor(int $vendor): void
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
@@ 34-43 (lines=10) @@
31
     * @param int $product
32
     * @throws InvalidValueException
33
     */
34
    private function setProduct(int $product): void
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
@@ 49-58 (lines=10) @@
46
     * @param int $version
47
     * @throws InvalidValueException
48
     */
49
    private function setVersion(int $version): void
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