Passed
Push — master ( 11e596...ed648f )
by Gabriel
13:25
created

HasHelpersTrait::getFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Nip\View\Extensions\Helpers;
4
5
use Nip\View\Helpers\DoctypeHelper;
6
7
/**
8
 * Trait HasHelpersTrait
9
 * @package Nip\View\Traits
10
 *
11
 * @method hasHelper($name)
12
 * @method getHelper($name)
13
 *
14
 * @method DoctypeHelper Doctype()
15
 *
16
 * @method Helpers\View\Breadcrumbs Breadcrumbs()
17
 * @method Helpers\View\Flash Flash()
18
 * @method Helpers\View\FacebookMeta FacebookMeta()
19
 * @method Helpers\View\GoogleAnalytics GoogleAnalytics()
20
 * @method Helpers\View\HTML HTML()
21
 * @method Helpers\View\Messages Messages()
22
 * @method Helpers\View\Meta Meta()
23
 * @method Helpers\View\Paginator Paginator()
24
 * @method Helpers\View\Scripts Scripts()
25
 * @method Helpers\View\Stylesheets Stylesheets()
26
 * @method Helpers\View\TinyMCE TinyMCE()
27
 * @method Helpers\View\Url Url()
28
 * @method Helpers\View\GoogleDFP GoogleDFP()
29
 */
30
trait HasHelpersTrait
31
{
32
    public function addHelpersExtension()
33 11
    {
34
        $this->loadExtension(new HelpersExtension());
0 ignored issues
show
Bug introduced by
It seems like loadExtension() 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

34
        $this->/** @scrutinizer ignore-call */ 
35
               loadExtension(new HelpersExtension());
Loading history...
35 11
    }
36 11
37
    /**
38
     * @inheritDoc
39
     */
40
    public function getFunction($name)
41
    {
42
        $this->initFunctionHelper($name);
43
        return parent::getFunction($name);
44
    }
45
46
47
    /**
48
     * @param $name
49
     * @return mixed
50
     */
51
    protected function initFunctionHelper($name)
52
    {
53
        if ($this->doesFunctionExist($name)) {
0 ignored issues
show
Bug introduced by
It seems like doesFunctionExist() 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

53
        if ($this->/** @scrutinizer ignore-call */ doesFunctionExist($name)) {
Loading history...
54
            return;
55
        }
56
        if ($this->hasHelper($name) === false) {
57
            return;
58
        }
59
        $this->registerFunction($name, function () use ($name) {
0 ignored issues
show
Bug introduced by
It seems like registerFunction() 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

59
        $this->/** @scrutinizer ignore-call */ 
60
               registerFunction($name, function () use ($name) {
Loading history...
60
            return $this->getHelper($name);
61
        });
62
    }
63
}
64