GSM7::isGSM7()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 6
Ratio 42.86 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 6
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
crap 3
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