MultiViewFinder   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 63
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A pushViewFinder() 0 4 1
A addViewFinder() 0 4 1
A findTemplate() 0 12 4
A listSearchPaths() 0 10 2
1
<?php
2
3
namespace mindplay\kisstpl;
4
5
/**
6
 * This view-finder aggregates a stack of view-finders and attempts to
7
 * locate views by trying every added view-finder in order - use this
8
 * for advanced (modular) "theme" scenarios, etc.
9
 */
10
class MultiViewFinder implements ViewFinder
11
{
12
    /**
13
     * @var ViewFinder[] stack of view-finders
14
     */
15
    protected $finders = array();
16
17
    /**
18
     * Add a view-finder to the top of the stack - the added view-finder will
19
     * have the highest priority of view-finders currently on the stack.
20
     *
21
     * @param ViewFinder $finder
22
     */
23 1
    public function pushViewFinder(ViewFinder $finder)
24
    {
25 1
        array_unshift($this->finders, $finder);
26 1
    }
27
28
    /**
29
     * Add a view-finder to the bottom of the stack - the added view-finder will
30
     * have the lowest priority of view-finders currently on the stack.
31
     *
32
     * @param ViewFinder $finder
33
     */
34 1
    public function addViewFinder(ViewFinder $finder)
35
    {
36 1
        $this->finders[] = $finder;
37 1
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @see ViewFinder::findTemplate()
43
     */
44 1
    public function findTemplate($view_model, $type)
45
    {
46 1
        foreach ($this->finders as $finder) {
47 1
            $path = $finder->findTemplate($view_model, $type);
48
49 1
            if ($path !== null && file_exists($path)) {
50 1
                return $path;
51
            }
52
        }
53
54 1
        return null;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     *
60
     * @see ViewFinder::listSearchPaths()
61
     */
62 1
    public function listSearchPaths($view_model, $type)
63
    {
64 1
        $paths = array();
65
66 1
        foreach ($this->finders as $finder) {
67 1
            $paths = array_merge($paths, $finder->listSearchPaths($view_model, $type));
68
        }
69
70 1
        return $paths;
71
    }
72
}
73