Renderer::render()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 3
nop 2
1
<?php
2
3
namespace Facade\Ignition\ErrorPage;
4
5
use Exception;
6
use Facade\Ignition\Exceptions\ViewException;
7
8
class Renderer
9
{
10
    /** @var string */
11
    protected $viewPath;
12
13
    public function __construct(string $viewPath)
14
    {
15
        $this->viewPath = $this->formatPath($viewPath);
16
    }
17
18
    public function render(string $viewName, array $_data): string
19
    {
20
        ob_start();
21
22
        $viewFile = "{$this->viewPath}/{$viewName}.php";
23
24
        try {
25
            extract((array) $_data, EXTR_OVERWRITE);
0 ignored issues
show
Bug introduced by
(array) $_data cannot be passed to extract() as the parameter $var_array expects a reference.
Loading history...
26
27
            include $viewFile;
28
        } catch (Exception $exception) {
29
            $viewException = new ViewException($exception->getMessage());
30
            $viewException->setView($viewFile);
31
            $viewException->setViewData($_data);
32
33
            throw $viewException;
34
        }
35
36
        return ob_get_clean();
37
    }
38
39
    protected function formatPath(string $path): string
40
    {
41
        return preg_replace('/(?:\/)+$/u', '', $path).'/';
42
    }
43
}
44