Completed
Push — master ( 325ba3...57475a )
by Camilo
98:41 queued 96:24
created

TopicName::getTopicName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\MQTT\DataTypes;
6
7
use unreal4u\MQTT\Exceptions\InvalidQoSLevel;
8
9
/**
10
 * This Value Object will always contain a valid topic name.
11
 */
12
final class TopicName {
13
    /**
14
     *
15
     * @var string
16
     */
17
    private $topicName;
18
19
    /**
20
     * Topic name constructor.
21
     *
22
     * @param string $topicName
23
     *
24
     * @throws \OutOfBoundsException
25
     * @throws \InvalidArgumentException
26
     */
27 6
    public function __construct(string $topicName)
28
    {
29 6
        if ($topicName === '') {
30 1
            throw new \InvalidArgumentException('Topic name must be at least 1 character long');
31
        }
32
33 5
        if (\strlen($topicName) > 65535) {
34 1
            throw new \OutOfBoundsException('Topic name can not exceed 65535 bytes');
35
        }
36
37 4
        $this->topicName = $topicName;
38 4
    }
39
40
    /**
41
     * Gets the current QoS level
42
     *
43
     * @return int
44
     */
45 4
    public function getTopicName(): string
46
    {
47 4
        return $this->topicName;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->topicName returns the type string which is incompatible with the documented return type integer.
Loading history...
48
    }
49
}
50