SlugifySlugifier::slugify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
3
namespace CSSPrites\Slugifier;
4
5
use URLify;
6
7
class SlugifySlugifier implements SlugifierInterface
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 48
    public function slugify($text)
13
    {
14 48
        $text = URLify::downcode($text);
15 48
        $text = preg_replace('/\b('.implode('|', URLify::$remove_list).')\b/i', '', $text);
16
17 48
        $text = preg_replace('/[^\s_\-a-zA-Z0-9]/u', '', $text); // remove unneeded chars
18 48
        $text = str_replace('_', ' ', $text);                    // treat underscores as spaces
19 48
        $text = preg_replace('/^\s+|\s+$/u', '', $text);         // trim leading/trailing spaces
20 48
        $text = preg_replace('/[-\s]+/u', '-', $text);           // convert spaces to hyphens
21 48
        $text = trim($text, '-');                                // trim to first $length chars
22
23 48
        return $text;
24
    }
25
}
26