StringHelper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 87
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A wordTranslit() 0 8 1
A arrayTranslit() 0 9 2
A removeSymbols() 0 4 1
A removeSpecifications() 0 6 1
1
<?php
2
3
namespace GeoFixer\helpers;
4
5
/**
6
 * Class StringHelper
7
 *
8
 * @package GeoFixer\helpers
9
 */
10
class StringHelper {
11
12
    /**
13
     * Массив букв для транслитерации
14
     *
15
     * @var array
16
     */
17
    public $alphabet = [
18
        "А"=>"A","Б"=>"B","В"=>"V","Г"=>"G",
19
        "Д"=>"D","Е"=>"E","Ё"=>"E","Ж"=>"J","З"=>"Z","И"=>"I",
20
        "Й"=>"Y","К"=>"K","Л"=>"L","М"=>"M","Н"=>"N",
21
        "О"=>"O","П"=>"P","Р"=>"R","С"=>"S","Т"=>"T",
22
        "У"=>"U","Ф"=>"F","Х"=>"Kh","Ц"=>"Ts","Ч"=>"Ch",
23
        "Ш"=>"Sh","Щ"=>"Sch","Ъ"=>"","Ы"=>"Yi","Ь"=>"",
24
        "Э"=>"E","Ю"=>"Yu","Я"=>"Ya","а"=>"a","б"=>"b",
25
        "в"=>"v","г"=>"g","д"=>"d","е"=>"e","ё"=>"e","ж"=>"j",
26
        "з"=>"z","и"=>"i","й"=>"y","к"=>"k","л"=>"l",
27
        "м"=>"m","н"=>"n","о"=>"o","п"=>"p","р"=>"r",
28
        "с"=>"s","т"=>"t","у"=>"u","ф"=>"f","х"=>"h",
29
        "ц"=>"ts","ч"=>"ch","ш"=>"sh","щ"=>"sch","ъ"=>"y",
30
        "ы"=>"yi","ь"=>"'","э"=>"e","ю"=>"yu","я"=>"ya",
31
32
        "Ą"=>"A",'Ć'=>'C',"Ę"=>"E",
33
        "Ł"=>"L","Ń"=>"N","Ó"=>"O",
34
        "Ś"=>"S","Ź"=>"Z","Ż"=>"Z",
35
        "ą"=>"a", "ę"=>"e","ł"=>"l",
36
        "ń"=>"n","ó"=>"o","ć"=>"c",
37
        "ś"=>"s","ź"=>"z","ż"=>"z",
38
    ];
39
40
    /**
41
     * Транслитерируем слово
42
     *
43
     * @param $word
44
     *
45
     * @return string
46
     */
47 20
    public function wordTranslit($word) {
48 20
        mb_internal_encoding("UTF-8");
49 20
        $word = mb_strtolower($word);
50 20
        $word = $this->removeSpecifications($word);
51 20
        $word = $this->removeSymbols($word);
52
53 20
        return strtr($word, $this->alphabet);
54
    }
55
56
    /**
57
     * Транслитерируем массив слов
58
     *
59
     * @param $array
60
     *
61
     * @return array
62
     */
63 19
    public function arrayTranslit($array) {
64 19
        $result = [];
65
66 19
        foreach ($array as $word) {
67 19
            $result[$word] = $this->wordTranslit($word);
68 19
        }
69
70 19
        return $result;
71
    }
72
73
    /**
74
     * Убираем пробелы и лишние символы, оставляем только кириллицу и латиницу
75
     *
76
     * @param $word
77
     * @return mixed
78
     */
79 21
    public function removeSymbols($word)
80
    {
81 21
        return preg_replace("/[^,\p{Cyrillic}\p{Latin}]/ui", '', $word);
82
    }
83
84
    /**
85
     * Убираем префиксы
86
     *
87
     * @param $word
88
     * @return mixed
89
     */
90 21
    public function removeSpecifications($word)
91
    {
92 21
        $search = include dirname(dirname(__FILE__)) . '/config/specifications.php';
93
94 21
        return str_ireplace($search, '', $word);
95
    }
96
}
97