Passed
Push — master ( 3d46a9...063abb )
by Valery
12:42 queued 08:19
created

Slugger::ascii()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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