Completed
Pull Request — master (#82)
by
unknown
14:09 queued 01:38
created

RuntimeOperator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A format() 0 22 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
        if (true === $shouldBreakString) {
26
            return sprintf(
27
                '".call_user_func_array(%s, [%s])."',
28
                $this->callable,
29
                join(',', array_map(function ($argument) {
30
                    if ('$' === $argument[0]) {
31
                        return $argument;
32
                    } else {
33
                        return sprintf('"%s"', $argument);
34
                    }
35
                }, $this->arguments))
36
            );
37
        } else {
38
            return sprintf(
39
                'call_user_func_array(%s, [%s])',
40
                $this->callable,
41
                join(',', $this->arguments)
42
            );
43
        }
44
    }
45
}