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::getExceptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
}