Callback   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 42
ccs 16
cts 16
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B transform() 0 29 5
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\TransformationException;
20
21
/**
22
 * Call a function and send back the result
23
 */
24
class Callback extends AbstractRule
25
{
26
    /**
27
     * Operate the transformation
28
     *
29
     * @param string $input
30
     * @param array  $arguments
31
     *
32
     * @throws Inet\Transformation\Exception\TransformationException
33
     *
34
     * @return string
35
     */
36 5
    public function transform($input, array $arguments)
37
    {
38
        // I should have two arguments: old format / new format
39 5
        if (count($arguments) === 0) {
40 1
            throw new TransformationException('Rule Callback Expects at least 1 argument');
41
        }
42
43 4
        $callable = $arguments[0];
44
45 4
        unset($arguments[0]);
46
        // Functions is callable ?
47 4
        if (!is_callable($callable)) {
48 1
            throw new TransformationException($callable.' is not callable');
49
        }
50
51
        // Transform it by calling the method and sending arguments
52
        // Process remaining arguments
53 3
        $args = array();
54 3
        if (count($arguments) > 0) {
55 2
            foreach ($arguments as $argument) {
56 2
                $args[] = $argument;
57 2
            }
58 2
        }
59
        // Inject the $input as the latest argument
60 3
        $args[] = $input;
61 3
        $output = call_user_func_array($callable, $args);
62
63 3
        return $output;
64
    }
65
}
66