ViewRenderFile   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 14 3
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