Implode::transform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
crap 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 Inet\Transformation\Exception\NotTransformableException;
20
use Inet\Transformation\Exception\TransformationException;
21
22
/**
23
 * Implode an array (useful after a callback)
24
 */
25
class Implode extends AbstractRule
26
{
27
    /**
28
     * Operate the transformation
29
     *
30
     * @param string $input
31
     * @param array  $arguments
32
     *
33
     * @throws Inet\Transformation\Exception\TransformationException
34
     *
35
     * @return string
36
     */
37 6
    public function transform($input, array $arguments)
38
    {
39
        // I should have two arguments: old format / new format
40 6
        if (count($arguments) !== 1) {
41 2
            throw new TransformationException('Rule Implode Expects exactly 1 argument');
42
        }
43
44 4
        if (!is_array($input)) {
45 1
            throw new NotTransformableException('Rule Implode can transform an array. '
46 1
                . gettype($input).' found in input');
47
        }
48
49
        // Transform it
50 3
        $output = implode($arguments[0], $input);
51
52 3
        return $output;
53
    }
54
}
55