Transliterator   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A slugify() 0 14 1
1
<?php
2
3
/**
4
 * Transliterator
5
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua)
6
 * @author Aleksandr Torosh <[email protected]>
7
 */
8
9
namespace Application\Localization;
10
11
class Transliterator
12
{
13
14
    public static function slugify($string)
15
    {
16
        $prepared       = str_replace(
17
                array('я', 'ю', 'ї', 'є', 'ж', 'ч', 'ш', 'щ', 'ь'), array('ya', 'yu', 'yi', 'ye', 'zh', 'ch', 'sh', 'sch', ''), $string);
18
        $transliterated = \Transliterator::create('Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();')->transliterate($prepared);
19
20
        $clean = preg_replace('/\W/i', '-', $transliterated);
21
22
        $replaced = str_replace('--', '-', $clean);
23
        $result   = preg_replace('/[[:^print:]]/', '', $replaced);
24
25
        return $result;
26
27
    }
28
29
}
30