Completed
Push — master ( a8687a...737d23 )
by Joachim
07:33
created

GSM7   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
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() 0 14 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 3
    public static function isGSM7(string $str) : bool
16
    {
17 3
        $alphabet = self::ALPHABET;
18
19 3
        $len = mb_strlen($str);
20 3
        for ($i = 0; $i < $len; $i++) {
21 3
            $char = mb_substr($str, $i, 1);
22 3
            if (!in_array($char, $alphabet)) {
23 3
                return false;
24
            }
25
        }
26
27 3
        return true;
28
    }
29
}
30