Total Complexity | 5 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
12 | final class TopicName extends GeneralTopicRules |
||
13 | { |
||
14 | /** |
||
15 | * The TopicName identifies the information channel to which payload data is published. |
||
16 | * |
||
17 | * @see http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718106 |
||
18 | * @var string |
||
19 | */ |
||
20 | private $topicName; |
||
21 | |||
22 | /** |
||
23 | * TopicName constructor. |
||
24 | * @param string $topicName |
||
25 | * @throws \OutOfBoundsException |
||
26 | * @throws \unreal4u\MQTT\Exceptions\InvalidQoSLevel |
||
27 | * @throws \InvalidArgumentException |
||
28 | */ |
||
29 | 48 | public function __construct(string $topicName) |
|
30 | { |
||
31 | 48 | $this->setTopicName($topicName); |
|
32 | 47 | } |
|
33 | |||
34 | /** |
||
35 | * Contains the name of the TopicFilter Filter |
||
36 | * |
||
37 | * @param string $topicName |
||
38 | * @return TopicFilter |
||
39 | * @throws \OutOfBoundsException |
||
40 | * @throws \InvalidArgumentException |
||
41 | */ |
||
42 | 48 | private function setTopicName(string $topicName): self |
|
43 | { |
||
44 | 48 | $this->generalRulesCheck($topicName); |
|
45 | |||
46 | // A topic name has some additional checks, as no wildcard characters are allowed |
||
47 | 48 | if (strpbrk($topicName, '#+') !== false) { |
|
48 | 1 | throw new \InvalidArgumentException('Topic names can not contain wildcard characters'); |
|
49 | } |
||
50 | |||
51 | 47 | $this->topicName = $topicName; |
|
52 | 47 | return $this; |
|
|
|||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | 15 | public function getTopicName(): string |
|
59 | { |
||
60 | 15 | return $this->topicName; |
|
61 | } |
||
62 | |||
63 | 1 | public function __toString() |
|
66 | } |
||
67 | } |
||
68 |