ChainWrapper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 47
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A value() 0 3 1
A __call() 0 12 3
1
<?php
2
3
namespace __\Traits\Sequence;
4
5
use __;
6
use Exception;
7
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)
21
    {
22 1
        $this->value = $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()
53
    {
54 1
        return $this->value;
55
    }
56
}
57