Skip to content

Commit 0858cd5

Browse files
tomzxbarryvdh
authored andcommitted
Extract exclusion logic to a separate function. (barryvdh#826)
Normalize the path to use the / separator to simplify logic and avoid usage of DIRECTORY_SEPARATOR.
1 parent b2d09d5 commit 0858cd5

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

src/DataCollector/QueryCollector.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,16 +218,9 @@ protected function parseTrace($index, array $trace)
218218
return $frame;
219219
}
220220

221-
if (isset($trace['class']) && isset($trace['file']) && strpos(
222-
$trace['file'],
223-
DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'laravel' . DIRECTORY_SEPARATOR . 'framework/src/Illuminate/Database'
224-
) === false && strpos(
225-
$trace['file'],
226-
DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'laravel' . DIRECTORY_SEPARATOR . 'framework/src/Illuminate/Events'
227-
) === false && strpos(
228-
$trace['file'],
229-
DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'barryvdh' . DIRECTORY_SEPARATOR . 'laravel-debugbar'
230-
) === false
221+
if (isset($trace['class']) &&
222+
isset($trace['file']) &&
223+
!$this->fileIsInExcludedPath($trace['file'])
231224
) {
232225
$file = $trace['file'];
233226

@@ -264,6 +257,31 @@ protected function parseTrace($index, array $trace)
264257
return false;
265258
}
266259

260+
/**
261+
* Check if the given file is to be excluded from analysis
262+
*
263+
* @param string $file
264+
* @return bool
265+
*/
266+
protected function fileIsInExcludedPath($file)
267+
{
268+
$excludedPaths = [
269+
'/vendor/laravel/framework/src/Illuminate/Database',
270+
'/vendor/laravel/framework/src/Illuminate/Events',
271+
'/vendor/barryvdh/laravel-debugbar',
272+
];
273+
274+
$normalizedPath = str_replace('\\', '/', $file);
275+
276+
foreach ($excludedPaths as $excludedPath) {
277+
if (strpos($normalizedPath, $excludedPath) !== false) {
278+
return true;
279+
}
280+
}
281+
282+
return false;
283+
}
284+
267285
/**
268286
* Find the middleware alias from the file.
269287
*

0 commit comments

Comments
 (0)