Completed
Push — master ( b71f7d...42978d )
by Konstantin
02:00
created

StringHelper::removeSymbols()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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","Ж"=>"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","ж"=>"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
33
    /**
34
     * Транслитерируем слово
35
     *
36
     * @param $word
37
     *
38
     * @return string
39
     */
40 20
    public function wordTranslit($word) {
41 20
        mb_internal_encoding("UTF-8");
42 20
        $word = $this->removeSpecifications($word);
43 20
        $word = mb_strtolower($word);
44 20
        $word = $this->removeSymbols($word);
45
46 20
        return strtr($word, $this->alphabet);
47
    }
48
49
    /**
50
     * Транслитерируем массив слов
51
     *
52
     * @param $array
53
     *
54
     * @return array
55
     */
56 19
    public function arrayTranslit($array) {
57 19
        $result = [];
58
59 19
        foreach ($array as $word) {
60 19
            $result[$word] = $this->wordTranslit($word);
61 19
        }
62
63 19
        return $result;
64
    }
65
66
    /**
67
     * Убираем пробелы и лишние символы, оставляем только кириллицу
68
     *
69
     * @param $word
70
     * @return mixed
71
     */
72 21
    public function removeSymbols($word)
73
    {
74 21
        return preg_replace('/[^а-яё]+/iu', '', $word);
75
    }
76
77
    /**
78
     * Убираем префиксы
79
     *
80
     * @param $word
81
     * @return mixed
82
     */
83 21
    public function removeSpecifications($word)
84
    {
85 21
        $search = include dirname(dirname(__FILE__)) . '/config/specifications.php';
86
87 21
        return str_ireplace($search, '', $word);
88
    }
89
}