DefaultViewFinder::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 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