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

HasViewFinder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 2
b 0
f 0
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A existPath() 0 8 2
A addPath() 0 3 1
A getFinder() 0 3 1
A prependPath() 0 3 1
1
<?php
2
3
namespace Nip\View\ResolveTemplatePath;
4
5
use League\Plates\Exception\TemplateNotFound;
6
use League\Plates\Template\Name;
7
8
/**
9
 * Trait HasViewFinder
10
 * @package Nip\View\ViewFinder
11
 */
12
trait HasViewFinder
13
{
14
15
    /**
16
     * Adds a path where templates are stored.
17
     *
18
     * @param string $path A path where to look for templates
19
     * @param string $namespace A path namespace
20
     *
21
     * @return void
22
     */
23
    public function addPath($path, $namespace = ThemeFolderResolveTemplatePath::MAIN_NAMESPACE)
24
    {
25
        $this->getResolveTemplatePath()->addPath($path, $namespace);
0 ignored issues
show
Bug introduced by
It seems like getResolveTemplatePath() 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

25
        $this->/** @scrutinizer ignore-call */ 
26
               getResolveTemplatePath()->addPath($path, $namespace);
Loading history...
26
    }
27
28
    /**
29
     * Prepends a path where templates are stored.
30
     *
31
     * @param string $path A path where to look for templates
32
     * @param string $namespace A path namespace
33
     * @return void
34
     */
35
    public function prependPath($path, $namespace = ThemeFolderResolveTemplatePath::MAIN_NAMESPACE)
36
    {
37
        $this->getResolveTemplatePath()->prependPath($path, $namespace);
38
    }
39
40
    /**
41
     * @param $view
42
     * @return bool
43
     */
44
    public function existPath($view): bool
45
    {
46
        try {
47
            $name = new Name($this, $view);
0 ignored issues
show
Bug introduced by
$this of type Nip\View\ResolveTemplatePath\HasViewFinder is incompatible with the type League\Plates\Engine expected by parameter $engine of League\Plates\Template\Name::__construct(). ( Ignorable by Annotation )

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

47
            $name = new Name(/** @scrutinizer ignore-type */ $this, $view);
Loading history...
48
            ($this->getResolveTemplatePath())($name);
49
            return true;
50
        } catch (TemplateNotFound $exception) {
51
            return false;
52
        }
53
    }
54
55
    /**
56
     * @deprecated use getResolveTemplatePath
57
     */
58
    public function getFinder(): \League\Plates\Template\ResolveTemplatePath
59
    {
60
        return $this->getResolveTemplatePath();
61
    }
62
}
63