Conditions | 6 |
Paths | 14 |
Total Lines | 71 |
Code Lines | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
60 | public function subRender($ex) |
||
61 | { |
||
62 | // Add support for HTTP library without having to necessarily depend on it |
||
63 | if (get_class($ex) === HttpException::class) { |
||
64 | /** @var HttpException $ex */ |
||
65 | $statusCode = $ex->getStatusCode(); |
||
66 | $headers = $ex->getHeaders(); |
||
67 | } else { |
||
68 | $statusCode = 500; |
||
69 | $headers = []; |
||
70 | } |
||
71 | |||
72 | // Always get the content, even if headers are sent, so that we can unit test this |
||
73 | $content = $ex->getMessage(); |
||
74 | |||
75 | if (!headers_sent()) { |
||
76 | header("HTTP/1.1 $statusCode", true, $statusCode); |
||
77 | |||
78 | switch ($this->getRequestFormat()) { |
||
79 | case 'json': |
||
80 | $headers['Content-Type'] = 'application/json'; |
||
81 | break; |
||
82 | default: |
||
83 | $content = sprintf( |
||
84 | '<!DOCTYPE html> |
||
85 | <html> |
||
86 | <head> |
||
87 | <meta name="viewport" content="initial-scale=1"/> |
||
88 | <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" |
||
89 | integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" |
||
90 | crossorigin="anonymous"> |
||
91 | </head> |
||
92 | <body> |
||
93 | <main class="main"> |
||
94 | <div class="container"> |
||
95 | <div class="row"> |
||
96 | <div class="col-sm"> |
||
97 | <div class="alert alert-danger" role="alert"> |
||
98 | <h4 class="alert-heading">Exception: %s</h4> |
||
99 | <p>%s</p> |
||
100 | <hr> |
||
101 | <p class="mb-0"> |
||
102 | <a href="#" class="btn btn-danger btn-lg active" role="button" aria-pressed="true" |
||
103 | onclick="location.reload(); return false;">Try again</a> |
||
104 | <a href="#" class="btn btn-primary btn-lg active" role="button" aria-pressed="true" |
||
105 | onclick="window.history.back(); return false;">Back to previous page</a> |
||
106 | </p> |
||
107 | </div> |
||
108 | </div> |
||
109 | </div> |
||
110 | </div> |
||
111 | </main> |
||
112 | </body> |
||
113 | </html>', |
||
114 | get_class($ex), |
||
115 | $ex->getMessage() |
||
116 | ); |
||
117 | $headers['Content-Type'] = 'text/html'; |
||
118 | } |
||
119 | |||
120 | foreach ($headers as $name => $values) { |
||
121 | $values = (array)$values; |
||
122 | |||
123 | foreach ($values as $value) { |
||
124 | header("$name:$value", false, $statusCode); |
||
125 | } |
||
126 | } |
||
127 | |||
128 | echo $content; |
||
129 | // To prevent any potential output buffering, let's flush |
||
130 | flush(); |
||
131 | } |
||
134 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.