DefaultViewFinder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 43
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findTemplate() 0 4 1
A listSearchPaths() 0 4 1
A __construct() 0 10 2
1
<?php
2
3
namespace mindplay\kisstpl;
4
5
/**
6
 * This view-finder maps a root namespace against a list of possible root paths,
7
 * defaulting to the first template that exists.
8
 */
9
class DefaultViewFinder implements ViewFinder
10
{
11
    /**
12
     * @var string|null base namespace for view-models supported by this finder
13
     */
14
    public $namespace;
15
16
    /**
17
     * @var MultiViewFinder
18
     */
19
    private $finders;
20
21
    /**
22
     * @param string[] $root_paths list of absolute paths to possible view root-folders (in order by priority)
23
     * @param string|null $namespace optional; base namespace for view-models supported by this finder
24
     */
25 1
    public function __construct(array $root_paths, $namespace = null)
26
    {
27 1
        $this->namespace = $namespace;
28
29 1
        $this->finders = new MultiViewFinder();
30
31 1
        foreach ($root_paths as $root_path) {
32 1
            $this->finders->addViewFinder(new SimpleViewFinder($root_path, $namespace));
33
        }
34 1
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39 1
    public function findTemplate($view_model, $type)
40
    {
41 1
        return $this->finders->findTemplate($view_model, $type);
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 1
    public function listSearchPaths($view_model, $type)
48
    {
49 1
        return $this->finders->listSearchPaths($view_model, $type);
50
    }
51
}
52