ProcessDatamap::createSlug()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 1
eloc 12
nc 1
nop 1
1
<?php
2
3
/**
4
 * Process data map
5
 */
6
7
namespace HDNET\Tagger\UserFunction;
8
9
/**
10
 * Class ProcessDatamap
11
 */
12
class ProcessDatamap
13
{
14
15
    /**
16
     * Call the pre process field array
17
     *
18
     * @param array $incomingFieldArray
19
     * @param string $table
20
     * @param integer $id
21
     * @param object $obj
22
     */
23
    public function processDatamap_preProcessFieldArray(&$incomingFieldArray, $table, $id, $obj)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        if ($table != 'tx_tagger_domain_model_tag') {
26
            return;
27
        }
28
29
        if ($incomingFieldArray['slug'] == '') {
30
            $incomingFieldArray['slug'] = $this->createSlug($incomingFieldArray['title']);
31
        }
32
    }
33
34
    /**
35
     * Create slug for the given title
36
     *
37
     * @param string $title
38
     * @return string
39
     * @author Martin Poelstra (from RealURL extension)
40
     */
41
    protected function createSlug($title)
42
    {
43
44
        // Convert to lowercase:
45
        $processedTitle = mb_strtolower($title);
46
47
        // Strip tags
48
        $processedTitle = strip_tags($processedTitle);
49
50
        // Convert some special tokens to the space character:
51
        $space = '-';
52
        $processedTitle = preg_replace('/[ \-+_]+/', $space, $processedTitle); // convert spaces
53
        // Convert extended letters to ascii equivalents:
54
        //$cs = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_cs');
55
        //$processedTitle = $cs->utf8_char_mapping($processedTitle, 'ascii');
56
57
        // Strip the rest...:
58
        $processedTitle = preg_replace('/[^a-zA-Z0-9\\' . $space . ']/', '', $processedTitle); // strip the rest
59
        $processedTitle = preg_replace(
60
            '/\\' . $space . '+/',
61
            $space,
62
            $processedTitle
63
        ); // Convert multiple 'spaces' to a single one
64
        $processedTitle = trim($processedTitle, $space);
65
66
        return $processedTitle;
67
    }
68
}
69