Slugify   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 31
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 18 3
1
<?php
2
/**
3
 * inetprocess/transformation
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @author Emmanuel Dyan
8
 * @copyright 2005-2015 iNet Process
9
 *
10
 * @package inetprocess/transformation
11
 *
12
 * @license GNU General Public License v2.0
13
 *
14
 * @link http://www.inetprocess.com
15
 */
16
17
namespace Inet\Transformation\Rule;
18
19
use Cocur\Slugify\Slugify as CocurSlugify;
20
use Inet\Transformation\Exception\NotTransformableException;
21
use Inet\Transformation\Exception\TransformationException;
22
23
/**
24
 * Replace a string with another
25
 */
26
class Slugify extends AbstractRule
27
{
28
    /**
29
     * Operate the transformation
30
     *
31
     * @param string $input
32
     * @param array  $arguments
33
     *
34
     * @throws Inet\Transformation\Exception\TransformationException
35
     *
36
     * @return string
37
     */
38 4
    public function transform($input, array $arguments)
39
    {
40
        // I should have two arguments: old format / new format
41 4
        if (count($arguments) !== 0) {
42 1
            throw new TransformationException('Rule Slugify Expects no parameter');
43
        }
44
45
        try {
46 3
            $slugify = new CocurSlugify();
47 3
            $output = $slugify->slugify($input);
48 3
        } catch (\Exception $e) {
49 1
            throw new NotTransformableException(
50 1
                'Rule Slugify: Unable to transform input ('.var_export($input, true).')'
51 1
            );
52
        }
53
54 2
        return $output;
55
    }
56
}
57