Slugger   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
eloc 7
c 3
b 2
f 0
dl 0
loc 17
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ascii() 0 3 1
A slugify() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * Created by PhpStorm.
6
 * User: Valery Maslov
7
 * Date: 30.08.2018
8
 * Time: 16:33.
9
 */
10
11
namespace App\Utils;
12
13
use Symfony\Component\String\Slugger\AsciiSlugger;
14
use voku\helper\ASCII;
15
16
final class Slugger implements SluggerInterface
17
{
18
    public static function slugify(string $string): string
19
    {
20
        if (!\function_exists('transliterator_transliterate')) {
21
            $string = self::ascii($string);
22
        }
23
24
        $slugger = new AsciiSlugger();
25
        $slug = $slugger->slug($string)->lower();
26
27
        return (string) $slug;
28
    }
29
30
    private static function ascii($value, $language = 'en'): string
31
    {
32
        return ASCII::to_ascii((string) $value, $language);
33
    }
34
}
35