|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Incidents View helper. |
|
5
|
|
|
* |
|
6
|
|
|
* phpMyAdmin Error reporting server |
|
7
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
|
8
|
|
|
* |
|
9
|
|
|
* Licensed under The MIT License |
|
10
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
11
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
12
|
|
|
* |
|
13
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
|
14
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
|
15
|
|
|
* |
|
16
|
|
|
* @see https://www.phpmyadmin.net/ |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace App\View\Helper; |
|
20
|
|
|
|
|
21
|
|
|
use function count; |
|
22
|
|
|
use function gettype; |
|
23
|
|
|
use function htmlspecialchars; |
|
24
|
|
|
use function implode; |
|
25
|
|
|
use function is_string; |
|
26
|
|
|
use function json_decode; |
|
27
|
|
|
use function strlen; |
|
28
|
|
|
use function substr; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Incidents View helper. |
|
32
|
|
|
*/ |
|
33
|
|
|
class IncidentsHelper extends AppHelper |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @param mixed $incidents |
|
37
|
|
|
* @return string comma separated list |
|
38
|
|
|
*/ |
|
39
|
4 |
|
public function createIncidentsLinks($incidents): string |
|
40
|
|
|
{ |
|
41
|
4 |
|
$links = []; |
|
42
|
4 |
|
foreach ($incidents as $incident) { |
|
43
|
4 |
|
$links[] = $this->linkToIncident($incident); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
4 |
|
return implode(', ', $links); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param mixed $incident The incident |
|
51
|
|
|
* @return string HTML <a> code |
|
52
|
|
|
*/ |
|
53
|
4 |
|
public function linkToIncident($incident): string |
|
54
|
|
|
{ |
|
55
|
4 |
|
$incidentId = $incident['id']; |
|
56
|
|
|
|
|
57
|
4 |
|
return '<a href="/' . BASE_DIR . 'incidents/view/' . $incidentId . '">#' . $incidentId . '</a>'; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param mixed $incidents The incidents |
|
62
|
|
|
* @return string HTML code |
|
63
|
|
|
*/ |
|
64
|
4 |
|
public function incidentsDescriptions($incidents): string |
|
65
|
|
|
{ |
|
66
|
4 |
|
$descriptions = ''; |
|
67
|
4 |
|
foreach ($incidents as $incident) { |
|
68
|
4 |
|
$descriptions .= '<span>Incident '; |
|
69
|
4 |
|
$descriptions .= $this->linkToIncident($incident); |
|
70
|
4 |
|
$descriptions .= ':</span>'; |
|
71
|
4 |
|
$descriptions .= '<pre>'; |
|
72
|
4 |
|
$descriptions .= htmlspecialchars($incident['steps']); |
|
73
|
4 |
|
$descriptions .= '</pre>'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
4 |
|
return $descriptions; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param mixed $incident The incident |
|
81
|
|
|
* @param stirng $divClass A class for the div |
|
|
|
|
|
|
82
|
|
|
* @return string HTML code |
|
83
|
|
|
*/ |
|
84
|
8 |
|
public function getStacktrace($incident, string $divClass): string |
|
85
|
|
|
{ |
|
86
|
8 |
|
$html = ''; |
|
87
|
8 |
|
$html .= '<div class="' . $divClass . '">'; |
|
88
|
|
|
|
|
89
|
8 |
|
if (is_string($incident['stacktrace'])) { |
|
90
|
4 |
|
$incident['stacktrace'] = |
|
91
|
4 |
|
json_decode($incident['stacktrace'], true); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
8 |
|
foreach ($incident['stacktrace'] as $level) { |
|
95
|
8 |
|
$exception_type = ($incident['exception_type'] ? 'php' : 'js'); |
|
96
|
8 |
|
$html .= $this->getStackLevelInfo($level, $exception_type); |
|
97
|
|
|
$html .= "<pre class='brush: " |
|
98
|
8 |
|
. $exception_type |
|
99
|
8 |
|
. '; tab-size: 2'; |
|
100
|
8 |
|
if (isset($level['line']) && $level['line']) { |
|
101
|
|
|
if ($incident['exception_type']) { |
|
102
|
|
|
$html .= '; first-line: ' . (int) $level['line']; |
|
103
|
|
|
} elseif ((int) $level['line'] > 5) { |
|
104
|
|
|
$html .= '; first-line: ' . ((int) $level['line'] - 5); |
|
105
|
|
|
} |
|
106
|
|
|
$html .= '; highlight: [' . (int) $level['line'] . ']'; |
|
107
|
|
|
} |
|
108
|
8 |
|
$html .= "'>"; |
|
109
|
|
|
|
|
110
|
8 |
|
if ($exception_type === 'js') { |
|
111
|
8 |
|
if (isset($level['context'])) { |
|
112
|
8 |
|
$html .= htmlspecialchars(implode("\n", $level['context'])); |
|
113
|
|
|
} |
|
114
|
|
|
} else { |
|
115
|
|
|
$html .= htmlspecialchars($level['function']); |
|
116
|
|
|
$html .= '('; |
|
117
|
|
|
$argList = ''; |
|
118
|
|
|
if (count($level['args']) > 0) { |
|
119
|
|
|
foreach ($level['args'] as $arg) { |
|
120
|
|
|
$argList .= "\n" |
|
121
|
|
|
. gettype($arg) |
|
122
|
|
|
. ' => ' |
|
123
|
|
|
. $arg; |
|
124
|
|
|
$argList .= ','; |
|
125
|
|
|
} |
|
126
|
|
|
$argList = substr($argList, 0, (strlen($argList) - 1)); |
|
127
|
|
|
$argList .= "\n"; |
|
128
|
|
|
} |
|
129
|
|
|
$html .= htmlspecialchars($argList); |
|
130
|
|
|
$html .= ')'; |
|
131
|
|
|
} |
|
132
|
8 |
|
$html .= '</pre>'; |
|
133
|
|
|
} |
|
134
|
8 |
|
$html .= '</div>'; |
|
135
|
|
|
|
|
136
|
8 |
|
return $html; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param mixed $level The level |
|
141
|
|
|
* @param string $exception_type The execption type (php/js) |
|
142
|
|
|
* @return string HTML code |
|
143
|
|
|
*/ |
|
144
|
8 |
|
protected function getStackLevelInfo($level, string $exception_type = 'js'): string |
|
145
|
|
|
{ |
|
146
|
8 |
|
$html = '<span>'; |
|
147
|
8 |
|
if ($exception_type === 'js') { |
|
148
|
|
|
$elements = [ |
|
149
|
8 |
|
'filename', |
|
150
|
|
|
'scriptname', |
|
151
|
|
|
'line', |
|
152
|
|
|
'func', |
|
153
|
|
|
'column', |
|
154
|
|
|
]; |
|
155
|
|
|
} else { |
|
156
|
|
|
$elements = [ |
|
157
|
|
|
'file', |
|
158
|
|
|
'line', |
|
159
|
|
|
'function', |
|
160
|
|
|
'class', |
|
161
|
|
|
]; |
|
162
|
|
|
} |
|
163
|
8 |
|
foreach ($elements as $element) { |
|
164
|
8 |
|
if (! isset($level[$element])) { |
|
165
|
8 |
|
continue; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
$html .= $element . ': ' . $level[$element] . '; '; |
|
169
|
|
|
} |
|
170
|
8 |
|
$html .= '</span>'; |
|
171
|
|
|
|
|
172
|
8 |
|
return $html; |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths