GeneralTopicRules::generalRulesCheck()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 16
ccs 8
cts 8
cp 1
rs 10
cc 4
nc 4
nop 1
crap 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