GeneralTopicRules   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generalRulesCheck() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace unreal4u\MQTT\Internals;
6
7
abstract class GeneralTopicRules
8
{
9
    /**
10
     * @param string $topic
11
     * @return bool
12
     * @throws \OutOfBoundsException
13
     * @throws \InvalidArgumentException
14
     */
15 69
    protected function generalRulesCheck(string $topic): bool
16
    {
17 69
        if ($topic === '') {
18 1
            throw (new \InvalidArgumentException('Topics must be at least 1 character long'));
19
        }
20
21
        // UTF-8 topic names and filters must not be more than 65535 bytes in size
22 68
        if (\strlen($topic) > 65535) {
23 1
            throw (new \OutOfBoundsException('Topics can not exceed 65535 bytes in size'));
24
        }
25
26 67
        if (strpos($topic, \chr(0)) !== false) {
27 1
            throw (new \InvalidArgumentException('Topics can not contain the termination character'));
28
        }
29
30 66
        return true;
31
    }
32
}
33