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

Html   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 4
c 5
b 0
f 1
lcom 1
cbo 1
dl 0
loc 37
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A report() 0 8 1
A constructViewInstance() 0 7 1
A setReportVariables() 0 7 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