SlugifySlugifier   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A slugify() 0 13 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