Slugger::slugify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 5
c 2
b 1
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
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