Issues (53)

src/ResolveTemplatePath/HasViewFinder.php (2 issues)

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

26
        $this->/** @scrutinizer ignore-call */ 
27
               getResolveTemplatePath()->addPath($path, $namespace);
Loading history...
27
    }
28
29
    /**
30
     * Prepends a path where templates are stored.
31
     *
32
     * @param string $path A path where to look for templates
33
     * @param string $namespace A path namespace
34
     *
35
     * @return void
36
     */
37
    public function prependPath($path, $namespace = ThemeFolderResolveTemplatePath::MAIN_NAMESPACE)
38
    {
39
        $this->getResolveTemplatePath()->prependPath($path, $namespace);
40
    }
41
42
    public function existPath($view): bool
43
    {
44
        try {
45
            $name = new Name($this, $view);
0 ignored issues
show
$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

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