Completed
Push — master ( faca0c...e03155 )
by Park Jong-Hun
03:46
created

Html::buildView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace App\ErrorReporter;
4
5
use Core\ViewEngineInterface;
6
use Core\ErrorReporterInterface;
7
use \Exception;
8
9
class Html implements ErrorReporterInterface
10
{
11
    private $settings = [];
12
13
    public function __construct($settings = [])
14
    {
15
        $this->settings = $settings;
16
    }
17
18
    public function report($exception)
19
    {
20
        $view = $this->constructViewInstance();
21
        $view->file($this->settings['file']);
22
        $this->setReportVariables($view, $exception);
23
24
        echo $view->render();
25
    }
26
27
    /**
28
     * @return ViewEngineInterface
29
     */
30
    private function constructViewInstance()
31
    {
32
        $viewClassName = $this->settings['view'];
33
        $view = new $viewClassName($this->settings);
34
35
        return $view;
36
    }
37
38
    private function setReportVariables(ViewEngineInterface $view, Exception $exception)
39
    {
40
        $view->set('message', $exception->getMessage());
41
        $view->set('file', $exception->getFile());
42
        $view->set('line', $exception->getLine());
43
        $view->set('traces', $exception->getTrace());
44
    }
45
}
46