Skip to content

Commit 1a52fbf

Browse files
committed
Do not reuse $line outside of foreach
1 parent 973ab18 commit 1a52fbf

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

system/Debug/Toolbar/Collectors/Database.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public function display(): array
134134
$data['queries'] = array_map(static function (array $query) {
135135
$isDuplicate = $query['duplicate'] === true;
136136

137+
$firstNonSystemLine = '';
138+
137139
foreach ($query['trace'] as $index => &$line) {
138140
// simplify file and line
139141
if (isset($line['file'])) {
@@ -143,6 +145,11 @@ public function display(): array
143145
$line['file'] = '[internal function]';
144146
}
145147

148+
// find the first trace line that does not originate from `system/`
149+
if ($firstNonSystemLine === '' && strpos($line['file'], 'SYSTEMPATH') === false) {
150+
$firstNonSystemLine = $line['file'];
151+
}
152+
146153
// simplify function call
147154
if (isset($line['class'])) {
148155
$line['function'] = $line['class'] . $line['type'] . $line['function'];
@@ -162,20 +169,6 @@ public function display(): array
162169
$line['index'] = $indexPadded . str_repeat(chr(0xC2) . chr(0xA0), 4);
163170
}
164171

165-
// remove the caller trace which is duplicated as the last item
166-
array_pop($query['trace']);
167-
168-
// Find the first line that doesn't include `system` in the backtrace
169-
$firstNonSystemLine = '';
170-
171-
foreach ($query['trace'] as $line) {
172-
if (strpos($line['file'], 'SYSTEMPATH') === false) {
173-
$firstNonSystemLine = $line['file'];
174-
175-
break;
176-
}
177-
}
178-
179172
return [
180173
'hover' => $isDuplicate ? 'This query was called more than once.' : '',
181174
'class' => $isDuplicate ? 'duplicate' : '',

tests/system/Debug/Toolbar/Collectors/DatabaseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public function testDisplay(): void
5454
$this->assertArrayHasKey('file', $trace);
5555

5656
// since we dropped object & args in the backtrace for performance
57+
// but args MAY STILL BE present in internal calls
5758
$this->assertArrayNotHasKey('object', $trace);
58-
$this->assertArrayNotHasKey('args', $trace);
5959
}
6060
}
6161
}

0 commit comments

Comments
 (0)