Passed
Push — master ( 4cb285...5a0531 )
by Mohamed
01:37
created

ChainWrapper::__call()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
crap 3.0261
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)) {
0 ignored issues
show
Bug introduced by
$functionName of type string is incompatible with the type boolean expected by parameter $syntax_only of is_callable(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
        if (is_callable('__', /** @scrutinizer ignore-type */ $functionName)) {
Loading history...
37 1
            $params = $params == null ? [] : $params;
0 ignored issues
show
introduced by
The condition $params == null can never be true.
Loading history...
38 1
            $params = __::prepend($params, $this->value);
39 1
            $this->value = call_user_func_array(['__', $functionName], $params);
40
41 1
            return $this;
42
        } else {
43
            throw new Exception("Invalid function {$functionName}");
44
        }
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50 1
    public function value()
51
    {
52 1
        return $this->value;
53
    }
54
}
55