Message::isUnicode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
namespace Loevgaard\Linkmobility\ValueObject;
3
4
use Loevgaard\Linkmobility\GSM7\GSM7;
5
6
class Message extends StringValueObject
7
{
8
    /**
9
     * @var bool
10
     */
11
    private $gsm7;
12
13 1
    public function chunkCount() : int
14
    {
15 1
        $length = $this->length();
16 1
        $lengthThreshold = $this->isGsm7() ? 160 : 70;
17
18 1
        if ($length > $lengthThreshold) {
19 1
            $chunkDivisor = $this->isGsm7() ? 153 : 67;
20 1
            return (int)ceil($length / $chunkDivisor);
21
        }
22
23 1
        return 1;
24
    }
25
26 2
    public function length() : int
27
    {
28 2
        $length = mb_strlen($this->value);
29
30 2
        if (!$this->isGsm7()) {
31 2
            return $length;
32
        }
33
34 2
        $doubles = GSM7::DOUBLES;
35
36 2 View Code Duplication
        for ($i = 0; $i < $length; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37 2
            $char = mb_substr($this->value, $i, 1);
38 2
            if (in_array($char, $doubles)) {
39 1
                $length++;
40
            }
41
        }
42
43 2
        return $length;
44
    }
45
46 6
    public function isGsm7() : bool
47
    {
48 6
        if (is_null($this->gsm7)) {
49 6
            $this->gsm7 = GSM7::isGSM7($this->value);
50
        }
51
52 6
        return $this->gsm7;
53
    }
54
55 1
    public function isUnicode() : bool
56
    {
57 1
        return !$this->isGsm7();
58
    }
59
}
60