LocalViewFinder::findTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
namespace mindplay\kisstpl;
4
5
use ReflectionClass;
6
7
/**
8
 * This view-finder assumes a local view-file located "locally", in the
9
 * same folder as the class-file, e.g.:
10
 *
11
 *     src/view/HomePage.php         # class file
12
 *     src/view/HomePage.view.php    # matching template (for default type "view")
13
 */
14
class LocalViewFinder implements ViewFinder
15
{
16
    /**
17
     * {@inheritdoc}
18
     *
19
     * @see ViewFinder::findTemplate()
20
     */
21 1
    public function findTemplate($view_model, $type)
22
    {
23 1
        $class = new ReflectionClass($view_model);
24
25 1
        $path = dirname($class->getFileName());
26
27 1
        $name = $class->getShortName();
28
29 1
        return $path . DIRECTORY_SEPARATOR . $name . ".{$type}.php";
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     *
35
     * @see ViewFinder::listSearchPaths()
36
     */
37 1
    public function listSearchPaths($view_model, $type)
38
    {
39 1
        return array_filter(array($this->findTemplate($view_model, $type)));
40
    }
41
}
42