Locator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 8
c 3
b 0
f 0
lcom 1
cbo 0
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A addRoot() 0 7 2
A locate() 0 11 4
1
<?php
2
namespace Tuum\View;
3
4
class Locator implements LocatorInterface
5
{
6
    /**
7
     * @var string[]
8
     */
9
    private $dirs = [];
10
11
    /**
12
     * @param string $root
13
     */
14
    public function __construct($root = null)
0 ignored issues
show
Unused Code introduced by
The parameter $root is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
15
    {
16
        $this->dirs = [];
17
        $roots      = func_get_args();
18
        foreach ($roots as $root) {
19
            $this->addRoot($root);
20
        }
21
    }
22
23
    /**
24
     * @param string $root
25
     */
26
    public function addRoot($root)
27
    {
28
        if (substr($root, -1) !== '/') {
29
            $root .= '/';
30
        }
31
        $this->dirs = array_merge([$root], $this->dirs);
32
    }
33
34
    /**
35
     * @param string $file
36
     * @return bool|string
37
     */
38
    public function locate($file)
39
    {
40
        $file = substr($file,0,1) ==='/' ? substr($file,1) : $file;
41
        foreach ($this->dirs as $system) {
42
            $location = $system . $file;
43
            if (file_exists($location)) {
44
                return $location;
45
            }
46
        }
47
        return false;
48
    }
49
}