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.
Completed
Pull Request — 3.x (#2549)
by
unknown
02:15
created

HtmlErrorMessage   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 104
Duplicated Lines 31.73 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 33
loc 104
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 5 1
A renderHtmlErrorMessage() 29 29 3
A renderHtmlException() 0 4 1
B renderHtmlExceptionOrError() 4 31 8

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Slim\Handlers\Renderables;
3
4
use Slim\Interfaces\RenderableInterface;
5
6
class HtmlErrorMessage implements RenderableInterface
7
{
8
9
    private $displayErrorDetails;
10
11
    public function render($args)
12
    {
13
        $this->displayErrorDetails = $args[1];
14
        return $this->renderHtmlErrorMessage($args[0]);
15
    }
16
17
18
    /**
19
     * Render HTML error page
20
     *
21
     * @param  \Exception $exception
22
     *
23
     * @return string
24
     */
25 View Code Duplication
    protected function renderHtmlErrorMessage(\Exception $exception)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $title = 'Slim Application Error';
28
29
        if ($this->displayErrorDetails) {
30
            $html = '<p>The application could not run because of the following error:</p>';
31
            $html .= '<h2>Details</h2>';
32
            $html .= $this->renderHtmlException($exception);
33
34
            while ($exception = $exception->getPrevious()) {
35
                $html .= '<h2>Previous exception</h2>';
36
                $html .= $this->renderHtmlExceptionOrError($exception);
37
            }
38
        } else {
39
            $html = '<p>A website error has occurred. Sorry for the temporary inconvenience.</p>';
40
        }
41
42
        $output = sprintf(
43
            "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" .
44
            "<title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana," .
45
            "sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{" .
46
            "display:inline-block;width:65px;}</style></head><body><h1>%s</h1>%s</body></html>",
47
            $title,
48
            $title,
49
            $html
50
        );
51
52
        return $output;
53
    }
54
55
    /**
56
     * Render exception as HTML.
57
     *
58
     * Provided for backwards compatibility; use renderHtmlExceptionOrError().
59
     *
60
     * @param \Exception $exception
61
     *
62
     * @return string
63
     */
64
    protected function renderHtmlException(\Exception $exception)
65
    {
66
        return $this->renderHtmlExceptionOrError($exception);
67
    }
68
69
    /**
70
     * Render exception or error as HTML.
71
     *
72
     * @param \Exception|\Error $exception
73
     *
74
     * @return string
75
     */
76
    protected function renderHtmlExceptionOrError($exception)
77
    {
78
        if (!$exception instanceof \Exception && !$exception instanceof \Error) {
0 ignored issues
show
Bug introduced by
The class Error does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
79
            throw new \RuntimeException("Unexpected type. Expected Exception or Error.");
80
        }
81
82
        $html = sprintf('<div><strong>Type:</strong> %s</div>', get_class($exception));
83
84
        if (($code = $exception->getCode())) {
85
            $html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
86
        }
87
88
        if (($message = $exception->getMessage())) {
89
            $html .= sprintf('<div><strong>Message:</strong> %s</div>', htmlentities($message));
90
        }
91
92
        if (($file = $exception->getFile())) {
93
            $html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
94
        }
95
96
        if (($line = $exception->getLine())) {
97
            $html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
98
        }
99
100 View Code Duplication
        if (($trace = $exception->getTraceAsString())) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
            $html .= '<h2>Trace</h2>';
102
            $html .= sprintf('<pre>%s</pre>', htmlentities($trace));
103
        }
104
105
        return $html;
106
    }
107
108
109
}