ErrorHandler::setErrorPagePath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\mvc\errorHandler;
4
5
use Whoops\Run;
6
use Whoops\Handler\PrettyPageHandler;
7
8
class ErrorHandler
9
{
10
11
    private $errorPagePath = '';
12
13
    public function register()
14
    {
15
        (new Run())->pushHandler(\ENV === 'dev'
0 ignored issues
show
Bug introduced by
The constant ENV was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
16
            ? new PrettyPageHandler()
17
            : function () {
18
                $errorPagePath = $this->getErrorPagePath();
19
                if ($errorPagePath && \file_exists($errorPagePath)) {
20
                    echo \file_get_contents($errorPagePath);
21
                } else {
22
                    echo 'System error';
23
                }
24
            })->register();
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function getErrorPagePath(): string
31
    {
32
        return $this->errorPagePath;
33
    }
34
35
    /**
36
     * @param string $errorPagePath
37
     */
38
    public function setErrorPagePath(string $errorPagePath)
39
    {
40
        $this->errorPagePath = $errorPagePath;
41
    }
42
}
43