Completed
Push — master ( faf679...9221e6 )
by Mohamed
11s
created

PhpLodashWrapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace __\Sequence;
4
5
use __;
6
7
class PhpLodashWrapper
8
{
9
    /**
10
     * @var mixed $value
11
     */
12
    private $value;
13
14
    /**
15
     * BottomlineWrapper constructor.
16
     *
17
     * @param mixed $value the value that is going to be chained
18
     */
19 1
    public function __construct($value)
20
    {
21 1
        $this->value = $value;
22 1
    }
23
24
    /**
25
     * Dynamically calls php-lodash functions, prepend the list of parameters with the current collection list
26
     *
27
     * @param string $functionName must be a valid php-lodash function
28
     * @param array  $params
29
     *
30
     * @return $this
31
     * @throws \Exception
32
     */
33 1
    public function __call($functionName, $params)
34
    {
35 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

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