GSM7   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 6
loc 21
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isGSM7() 6 14 3

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\GSM7;
3
4
/**
5
 * See character set here
6
 *
7
 * @link https://en.wikipedia.org/wiki/GSM_03.38
8
 */
9
class GSM7
10
{
11
    // notice that we did not add the ESC, FF, SS2, and CR2 characters
12
    const ALPHABET = ["\n", "\r", ' ', '_', '-', ',', ';', ':', '!', '¡', '?', '¿', '.', "'", '"', '(', ')', '[', ']', '{', '}', '§', '@', '*', '/', '\\', '&', '#', '%', '^', '+', '<', '=', '>', '|', '~', '¤', '$', '£', '¥', '€', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'A', 'à', 'å', 'Å', 'ä', 'Ä', 'æ', 'Æ', 'b', 'B', 'c', 'C', 'Ç', 'd', 'D', 'e', 'E', 'é', 'É', 'è', 'f', 'F', 'g', 'G', 'h', 'H', 'i', 'I', 'ì', 'j', 'J', 'k', 'K', 'l', 'L', 'm', 'M', 'n', 'N', 'ñ', 'Ñ', 'o', 'O', 'ò', 'ö', 'Ö', 'ø', 'Ø', 'p', 'P', 'q', 'Q', 'r', 'R', 's', 'S', 'ß', 't', 'T', 'u', 'U', 'ù', 'ü', 'Ü', 'v', 'V', 'w', 'W', 'x', 'X', 'y', 'Y', 'z', 'Z', 'Γ', 'Δ', 'Θ', 'Λ', 'Ξ', 'Π', 'Σ', 'Φ', 'Ψ', 'Ω'];
13
    const DOUBLES = ['|', '^', '€', '{', '}', '[', ']', '~', '\\'];
14
15 7
    public static function isGSM7(string $str) : bool
16
    {
17 7
        $alphabet = self::ALPHABET;
18
19 7
        $len = mb_strlen($str);
20 7 View Code Duplication
        for ($i = 0; $i < $len; $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...
21 7
            $char = mb_substr($str, $i, 1);
22 7
            if (!in_array($char, $alphabet)) {
23 5
                return false;
24
            }
25
        }
26
27 5
        return true;
28
    }
29
}
30