GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ExceptionHandler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 10
cts 13
cp 0.7692
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addExceptions() 0 4 1
A getExceptions() 0 4 1
A handler() 0 8 2
1
<?php
2
3
namespace PhpBoot\Controller;
4
5
6
use PhpBoot\Application;
7
8
class ExceptionHandler
9
{
10 4
    public function __construct()
11
    {
12 4
        $this->renderer = new ExceptionRenderer();
0 ignored issues
show
Bug introduced by
The property renderer does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13 4
    }
14
15
    /**
16
     * @param string $name
17
     * @param string $doc
18
     */
19 3
    public function addExceptions($name, $doc)
20
    {
21 3
        $this->exceptions[] = [$name, $doc];
22 3
    }
23
24
    /*
25
     * @return array
26
     * 返回包含异常类型和描述的数组
27
     * 示例
28
     * [
29
     *      ['NotFoundHttpException', '这是说明'],
30
     *      ['ForbiddenHttpException', '这是说明'],
31
     * ]
32
     */
33 1
    public function getExceptions()
34
    {
35 1
        return $this->exceptions;
36
    }
37
38
    /**
39
     * @var array
40
     * 示例
41
     * [
42
     *      ['NotFoundHttpException', '这是说明'],
43
     *      ['ForbiddenHttpException', '这是说明'],
44
     * ]
45
     */
46
    private $exceptions = [];
47
48
    /**
49
     * @param Application $app
50
     * @param callable $call
51
     * @return \Symfony\Component\HttpFoundation\Response
52
     */
53 1
    public function handler(Application $app, callable $call){
54
        try{
55 1
            return $call();
56
        }catch (\Exception $e){
57
            $renderer = $app->get(ExceptionRenderer::class); //TODO 放在这里是否合适
58
            return $renderer->render($e);
59
        }
60
    }
61
}