Total Complexity | 6 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | trait FunctionCallTrait |
||
17 | { |
||
18 | /** |
||
19 | * @var string $placeholder The value that will be replaced by the chain subject |
||
20 | */ |
||
21 | protected $placeholder = '$$'; |
||
22 | /** |
||
23 | * Prepare the arguments list. |
||
24 | * @param array $args |
||
25 | * @param mixed $value |
||
26 | * @return array |
||
27 | */ |
||
28 | protected function prepareArgs(array $args, $value) |
||
29 | { |
||
30 | return $this->hasPlaceholder($args) ? $this->replacePlaceholderWithValue($args, $value) : $this->addValueAsFirstArg($args, $value); |
||
31 | } |
||
32 | /** |
||
33 | * Check if an array contains an element matching the placeholder. |
||
34 | * @param array $args |
||
35 | * @return bool |
||
36 | */ |
||
37 | protected function hasPlaceholder(array $args) |
||
40 | } |
||
41 | /** |
||
42 | * Add the value as the first argument in the arguments list. |
||
43 | * @param array $args |
||
44 | * @param mixed $value |
||
45 | * @return array |
||
46 | */ |
||
47 | protected function addValueAsFirstArg(array $args, $value) |
||
48 | { |
||
49 | array_unshift($args, $value); |
||
50 | return $args; |
||
51 | } |
||
52 | /** |
||
53 | * Replace any occurrence of the placeholder with the value. |
||
54 | * @param array $args |
||
55 | * @param mixed $value |
||
56 | * @return array |
||
57 | */ |
||
58 | protected function replacePlaceholderWithValue(array $args, $value) |
||
63 | } |
||
64 | } |