GenerateSlug   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateSlug() 0 10 1
1
<?php
2
3
namespace Fillet\TextUtils;
4
5
/**
6
 * Helper trait for generating properly slugged titles
7
 *
8
 * @package Fillet\TextUtils
9
 */
10
trait GenerateSlug
11
{
12
    /**
13
     * Generate an appropriate slug from a title
14
     * This function will turn a title into a lowercase and hyphenated title that is compatible with how Sculpin expects
15
     * slugs.
16
     *
17
     * @param string $title Raw title
18
     *
19
     * @return string
20
     */
21
    public function generateSlug($title)
22
    {
23
        $title = strtolower($title);
24
        $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
25
        $title = preg_replace('/\s+/', '-', $title);
26
        $title = preg_replace('|-+|', '-', $title);
27
        $title = trim($title, '-');
28
29
        return $title;
30
    }
31
}