1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LeKoala\DebugBar; |
4
|
|
|
|
5
|
|
|
use SilverStripe\ORM\DataList; |
6
|
|
|
use SilverStripe\ORM\DB; |
7
|
|
|
|
8
|
|
|
class DebugBarUtils |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Format a sql query string using available formatters. |
13
|
|
|
* If no formatters are available, simply return the string as is. |
14
|
|
|
* Highlighting is used if not in cli context |
15
|
|
|
*/ |
16
|
|
|
public static function formatSql(string $query): string |
17
|
|
|
{ |
18
|
|
|
if (class_exists(\Doctrine\SqlFormatter\SqlFormatter::class)) { |
19
|
|
|
return (new \Doctrine\SqlFormatter\SqlFormatter())->format($query); |
20
|
|
|
} |
21
|
|
|
if (class_exists(\SqlFormatter::class)) { |
|
|
|
|
22
|
|
|
return \SqlFormatter::format($query, !self::isCli()); |
23
|
|
|
} |
24
|
|
|
if (class_exists(\SilverStripe\View\Parsers\SQLFormatter::class)) { |
25
|
|
|
$method = self::isCli() ? 'formatPlain' : 'formatHTML'; |
26
|
|
|
$formatter = new \SilverStripe\View\Parsers\SQLFormatter; |
27
|
|
|
return $formatter->$method($query); |
28
|
|
|
} |
29
|
|
|
return $query; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Show the underlying sql query for a list |
34
|
|
|
* @param DataList $list |
35
|
|
|
* @param bool $inline Inlines paramters |
36
|
|
|
* @param bool $noQuotes Remove ANSI Quotes |
37
|
|
|
* @return string |
38
|
|
|
*/ |
39
|
|
|
public static function formatListQuery(DataList $list, bool $inline = true, bool $noQuotes = false): string |
40
|
|
|
{ |
41
|
|
|
$parameters = []; |
42
|
|
|
$formatted = self::formatSql($list->sql($parameters)); |
43
|
|
|
if ($inline) { |
44
|
|
|
$formatted = DB::inline_parameters($formatted, $parameters); |
45
|
|
|
} |
46
|
|
|
if ($noQuotes) { |
47
|
|
|
$formatted = str_replace('"', '', $formatted); |
48
|
|
|
} |
49
|
|
|
return $formatted; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function isCli(): bool |
53
|
|
|
{ |
54
|
|
|
return in_array(PHP_SAPI ?: '', ['cli', 'phpdbg']) || !http_response_code(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
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