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

HasPathsTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initBasePath() 0 3 1
A getBasePath() 0 7 2
A generateBasePath() 0 7 2
A setBasePath() 0 6 1
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