Completed
Push — master ( d37c8b...c70816 )
by Camilo
02:32
created

GeneralTopicRules   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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 68
    protected function generalRulesCheck(string $topic): bool
16
    {
17 68
        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 67
        if (\strlen($topic) > 65535) {
23 1
            throw new \OutOfBoundsException('Topics can not exceed 65535 bytes in size');
24
        }
25
26 66
        if (strpos($topic, \chr("\n")) !== false) {
0 ignored issues
show
Bug introduced by
' ' of type string is incompatible with the type integer expected by parameter $ascii of chr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        if (strpos($topic, \chr(/** @scrutinizer ignore-type */ "\n")) !== false) {
Loading history...
27 1
            throw new \InvalidArgumentException('Topics can not contain the termination character');
28
        }
29
30 65
        return true;
31
    }
32
}
33