ViewRenderFile::render()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 2
dl 0
loc 14
ccs 0
cts 10
cp 0
crap 12
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\View;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
/**
9
 * Render a view based on a template file and a dataset.
10
 */
11
class ViewRenderFile implements
12
    ViewRenderFileInterface,
13
    ContainerInjectableInterface
14
{
15
    use ContainerInjectableTrait;
16
17
18
19
    /**
20
     * Render the view file.
21
     *
22
     * @param string $file to include as view file.
23
     * @param array  $data to expose within the view.
24
     *
25
     * @throws \Anax\View\Exception when template file is not found.
26
     *
27
     * @return void
28
     */
29
    public function render(string $file, array $data) : void
30
    {
31
        if (!is_readable($file)) {
32
            throw new Exception("Could not find template file: " . $this->template);
0 ignored issues
show
Bug introduced by
The property template does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
        }
34
35
        $di = $this->di;
36
        $app = null;
37
        if ($di->has("app")) {
38
            $app = $di->get("app");
39
        }
40
        extract($data);
41
        require $file;
42
    }
43
}
44