HasMethodsTrait::addMethods()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nip\View\Traits;
6
7
use Closure;
8
9
/**
10
 * Trait HasMethodsTrait.
11
 */
12
trait HasMethodsTrait
13
{
14
    /**
15
     * Magic method used to call extension functions.
16
     *
17 11
     * @param string $name
18
     * @param array $arguments
19 11
     *
20 11
     * @return mixed
21
     */
22
    public function __call($name, $arguments)
23
    {
24
        return $this->getFunction($name)->call(null, $arguments);
0 ignored issues
show
Bug introduced by
The method getFunction() does not exist on Nip\View\Traits\HasMethodsTrait. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

24
        return $this->/** @scrutinizer ignore-call */ getFunction($name)->call(null, $arguments);
Loading history...
25 11
    }
26
27 11
    public function addMethod($name, callable $callable): void
28 11
    {
29
        $this->registerFunction($name, $callable);
0 ignored issues
show
Bug introduced by
The method registerFunction() does not exist on Nip\View\Traits\HasMethodsTrait. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

29
        $this->/** @scrutinizer ignore-call */ 
30
               registerFunction($name, $callable);
Loading history...
30
    }
31 11
32
    /**
33
     * @param Closure[] $methods
34
     */
35
    public function addMethods(array $methods)
36
    {
37 11
        foreach ($methods as $name => $closure) {
38
            $this->addMethod($name, $closure);
39 11
        }
40 11
    }
41
}
42