Completed
Pull Request — master (#82)
by
unknown
16:22 queued 08:47
created

RuntimeOperator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B format() 0 24 3
1
<?php
2
3
namespace RulerZ\Target\Operators;
4
5
class RuntimeOperator
6
{
7
    /**
8
     * @var string
9
     */
10
    private $callable;
11
12
    /**
13
     * @var array
14
     */
15
    private $arguments;
16
17
    public function __construct($callable, $arguments)
18
    {
19
        $this->callable = $callable;
20
        $this->arguments = $arguments;
21
    }
22
23
    public function format($shouldBreakString)
24
    {
25
        $formattedArguments = join(',', array_map(function ($argument) {
26
            if ('$' === $argument[0]) {
27
                return $argument;
28
            } else {
29
                return sprintf('"%s"', $argument);
30
            }
31
        }, $this->arguments));
32
33
        if (true === $shouldBreakString) {
34
            return sprintf(
35
                '".call_user_func_array(%s, [%s])."',
36
                $this->callable,
37
                $formattedArguments
38
            );
39
        } else {
40
            return sprintf(
41
                'call_user_func_array(%s, [%s])',
42
                $this->callable,
43
                $formattedArguments
44
            );
45
        }
46
    }
47
}
48