ExceptionHandler::handle()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 13
rs 9.2
cc 4
eloc 9
nc 4
nop 0
1
<?php
2
3
namespace Core\Exceptions;
4
5
use Exception;
6
use Invoker\Exception\NotCallableException;
7
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
8
9
class ExceptionHandler
10
{
11
    private $exception;
12
13
    public function __construct(Exception $e)
14
    {
15
        $this->exception = $e;
16
        $this->handle();
17
    }
18
19
    public function handle()
20
    {
21
        if ($this->exception instanceof AuthException) {
22
            die('User must be logged in');
0 ignored issues
show
Coding Style Compatibility introduced by
The method handle() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
23
        } elseif ($this->exception instanceof NotCallableException) {
24
            die('Method not found');
0 ignored issues
show
Coding Style Compatibility introduced by
The method handle() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
25
        }
26
        if ($this->exception instanceof MethodNotAllowedException) {
27
            die('Not allowed');
0 ignored issues
show
Coding Style Compatibility introduced by
The method handle() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
28
        } else {
29
            echo $this->exception->getMessage();
30
        }
31
    }
32
}
33