Completed
Pull Request — master (#82)
by
unknown
02:06
created

RuntimeOperator::format()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 3
eloc 17
nc 2
nop 1
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