Completed
Push — master ( 22c257...e714e6 )
by Gabriel
13:14 queued 10:09
created

HasMethodsTrait::getEngineMethods()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\View\Traits;
4
5
use Closure;
6
use Nip\View\Methods\MethodsCollection;
7
use Nip\View\Methods\Pipeline\Stages\MethodCollectionStage;
8
9
/**
10
 * Trait HasMethodsTrait
11
 * @package Nip\View\Traits
12
 */
13
trait HasMethodsTrait
14
{
15
    protected $engineMethods = null;
16
17 6
    public function addMethodsPipelineStage()
18
    {
19 6
        $this->addCallPipeline(new MethodCollectionStage());
0 ignored issues
show
Bug introduced by
It seems like addCallPipeline() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

19
        $this->/** @scrutinizer ignore-call */ 
20
               addCallPipeline(new MethodCollectionStage());
Loading history...
20 6
    }
21
22
    /**
23
     * @return MethodsCollection
24
     */
25 6
    public function getEngineMethods(): MethodsCollection
26
    {
27 6
        if ($this->engineMethods === null) {
28 6
            $this->initEngineMethods();
29
        }
30
31 6
        return $this->engineMethods;
32
    }
33
34
    /**
35
     * @param MethodsCollection $engineMethods
36
     */
37 6
    public function setEngineMethods(MethodsCollection $engineMethods): void
38
    {
39 6
        $this->engineMethods = $engineMethods;
40 6
    }
41
42
    /**
43
     * @param $name
44
     * @param Closure $callable
45
     */
46 6
    public function addMethod($name, Closure $callable)
47
    {
48 6
        $this->getEngineMethods()->set($name, $callable);
49 6
    }
50
51
    /**
52
     * @param Closure[] $methods
53
     */
54
    public function addMethods(array $methods)
55
    {
56
        foreach ($methods as $name => $closure) {
57
            $this->addMethod($name, $closure);
58
        }
59
    }
60
61 6
    protected function initEngineMethods()
62
    {
63 6
        $methods = $this->newEngineMethods();
64 6
        $this->setEngineMethods($methods);
65 6
    }
66
67
    /**
68
     * @return MethodsCollection
69
     */
70 6
    protected function newEngineMethods()
71
    {
72 6
        return new MethodsCollection();
73
    }
74
}
75