ExceptionHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 13 4
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