Message   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 54
Duplicated Lines 11.11 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 6
loc 54
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A chunkCount() 0 12 4
A isGsm7() 0 8 2
A isUnicode() 0 4 1
A length() 6 19 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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