SluggableHelper::getSlug()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 8
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace Suilven\Sluggable\Helper;
4
5
use SilverStripe\View\Parsers\URLSegmentFilter;
6
7
class SluggableHelper
8
{
9
    /**
10
     * Convert the configured field and it's associated value into a slug
11
     * e.g. Liverpool Football Club => liverpool-football-club
12
     *
13
     * @param string $fieldValue The value of the field
14
     * @return string field value sluggified
15
     */
16
    public function getSlug(string $fieldValue): string
17
    {
18
19
        // use the standard SilverStripe tool for slugging URLs.  This optionally may have a different transliterator
20
        // associated with it
21
        $slugger = new URLSegmentFilter();
22
23
        return $slugger->filter($fieldValue);
24
    }
25
}
26