Total Complexity | 5 |
Total Lines | 47 |
Duplicated Lines | 0 % |
Coverage | 92.31% |
Changes | 0 |
1 | <?php |
||
8 | class ChainWrapper |
||
9 | { |
||
10 | /** |
||
11 | * @var mixed $value |
||
12 | */ |
||
13 | private $value; |
||
14 | |||
15 | /** |
||
16 | * Php-lodash constructor. |
||
17 | * |
||
18 | * @param mixed $value the value that is going to be chained |
||
19 | */ |
||
20 | 1 | public function __construct($value) |
|
23 | 1 | } |
|
24 | |||
25 | /** |
||
26 | * Dynamically calls php-lodash functions, prepend the list of parameters with the current collection list |
||
27 | * |
||
28 | * @param string $functionName must be a valid php-lodash function |
||
29 | * @param array $params |
||
30 | * |
||
31 | * @return $this |
||
32 | * @throws \Exception |
||
33 | */ |
||
34 | 1 | public function __call(string $functionName, array $params): self |
|
35 | { |
||
36 | 1 | if (is_callable('\__::' . $functionName, true)) { |
|
37 | 1 | $params = $params == null ? [] : $params; |
|
38 | 1 | $params = __::prepend($params, $this->value); |
|
39 | /** @var callable $fnCallable */ |
||
40 | 1 | $fnCallable = ['\__', $functionName]; |
|
41 | 1 | $this->value = call_user_func_array($fnCallable, $params); |
|
42 | |||
43 | 1 | return $this; |
|
44 | } else { |
||
45 | throw new Exception("Invalid function {$functionName}"); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * @return mixed |
||
51 | */ |
||
52 | 1 | public function value() |
|
55 | } |
||
56 | } |
||
57 |