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

HasPathsTrait::setBasePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\View\Traits;
4
5
/**
6
 * Trait HasPathsTrait
7
 * @package Nip\View\Traits
8
 */
9
trait HasPathsTrait
10
{
11
    protected $basePath = null;
12
13
    /**
14
     * @return string
15
     */
16 6
    public function getBasePath()
17
    {
18 6
        if ($this->basePath === null) {
19 6
            $this->initBasePath();
20
        }
21
22 6
        return $this->basePath;
23
    }
24
25
    /**
26
     * @param string $path
27
     * @return $this
28
     */
29 6
    public function setBasePath($path)
30
    {
31 6
        $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
32 6
        $this->basePath = $path;
33 6
        $this->getFinder()->setPaths($path);
0 ignored issues
show
Bug introduced by
It seems like getFinder() 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

33
        $this->/** @scrutinizer ignore-call */ 
34
               getFinder()->setPaths($path);
Loading history...
34 6
        return $this;
35
    }
36
37 6
    protected function initBasePath()
38
    {
39 6
        $this->setBasePath($this->generateBasePath());
40 6
    }
41
42
    /**
43
     * @return string
44
     */
45 6
    protected function generateBasePath()
46
    {
47 6
        if (defined('VIEWS_PATH')) {
48
            return VIEWS_PATH;
0 ignored issues
show
Bug introduced by
The constant Nip\View\Traits\VIEWS_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
49
        }
50
51 6
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
52
    }
53
}
54