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

HtmlPhpErrorMessage   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 76
Duplicated Lines 43.42 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 5 1
A renderHtmlPhpErrorMessage() 29 29 3
B renderHtmlError() 4 27 6

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 HtmlPhpErrorMessage implements RenderableInterface
7
{
8
9
    private $displayErrorDetails;
10
11
    public function render($args)
12
    {
13
        $this->displayErrorDetails = $args[1];
14
        return $this->renderHtmlPhpErrorMessage($args[0]);
15
    }
16
17 View Code Duplication
    protected function renderHtmlPhpErrorMessage(\Throwable $error)
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...
18
    {
19
        $title = 'Slim Application Error';
20
21
        if ($this->displayErrorDetails) {
22
            $html = '<p>The application could not run because of the following error:</p>';
23
            $html .= '<h2>Details</h2>';
24
            $html .= $this->renderHtmlError($error);
25
26
            while ($error = $error->getPrevious()) {
27
                $html .= '<h2>Previous error</h2>';
28
                $html .= $this->renderHtmlError($error);
29
            }
30
        } else {
31
            $html = '<p>A website error has occurred. Sorry for the temporary inconvenience.</p>';
32
        }
33
34
        $output = sprintf(
35
            "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" .
36
            "<title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana," .
37
            "sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{" .
38
            "display:inline-block;width:65px;}</style></head><body><h1>%s</h1>%s</body></html>",
39
            $title,
40
            $title,
41
            $html
42
        );
43
44
        return $output;
45
    }
46
47
    /**
48
     * Render error as HTML.
49
     *
50
     * @param \Throwable $error
51
     *
52
     * @return string
53
     */
54
    protected function renderHtmlError(\Throwable $error)
55
    {
56
        $html = sprintf('<div><strong>Type:</strong> %s</div>', get_class($error));
57
58
        if (($code = $error->getCode())) {
59
            $html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
60
        }
61
62
        if (($message = $error->getMessage())) {
63
            $html .= sprintf('<div><strong>Message:</strong> %s</div>', htmlentities($message));
64
        }
65
66
        if (($file = $error->getFile())) {
67
            $html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
68
        }
69
70
        if (($line = $error->getLine())) {
71
            $html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
72
        }
73
74 View Code Duplication
        if (($trace = $error->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...
75
            $html .= '<h2>Trace</h2>';
76
            $html .= sprintf('<pre>%s</pre>', htmlentities($trace));
77
        }
78
79
        return $html;
80
    }
81
}