Skip to content

Commit

Permalink
Do not reuse $line outside of foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Jan 7, 2022
1 parent 973ab18 commit 2f23f70
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions system/Debug/Toolbar/Collectors/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public function display(): array
$data['queries'] = array_map(static function (array $query) {
$isDuplicate = $query['duplicate'] === true;

$firstNonSystemLine = '';

foreach ($query['trace'] as $index => &$line) {
// simplify file and line
if (isset($line['file'])) {
Expand All @@ -143,6 +145,11 @@ public function display(): array
$line['file'] = '[internal function]';
}

// find the first trace line that does not originate from `system/`
if ($firstNonSystemLine === '' && strpos($line['file'], 'SYSTEMPATH') === false) {
$firstNonSystemLine = $line['file'];
}

// simplify function call
if (isset($line['class'])) {
$line['function'] = $line['class'] . $line['type'] . $line['function'];
Expand All @@ -162,20 +169,6 @@ public function display(): array
$line['index'] = $indexPadded . str_repeat(chr(0xC2) . chr(0xA0), 4);
}

// remove the caller trace which is duplicated as the last item
array_pop($query['trace']);

// Find the first line that doesn't include `system` in the backtrace
$firstNonSystemLine = '';

foreach ($query['trace'] as $line) {
if (strpos($line['file'], 'SYSTEMPATH') === false) {
$firstNonSystemLine = $line['file'];

break;
}
}

return [
'hover' => $isDuplicate ? 'This query was called more than once.' : '',
'class' => $isDuplicate ? 'duplicate' : '',
Expand Down

0 comments on commit 2f23f70

Please sign in to comment.