@@ -60,12 +60,11 @@ public function __construct(
60
60
/**
61
61
* Format the whitespace in a SQL string to make it easier to read.
62
62
*
63
- * @param string $string The SQL string
64
- * @param bool $highlight If true, syntax highlighting will also be performed
63
+ * @param string $string The SQL string
65
64
*
66
65
* @return string The SQL string with HTML styles and formatting wrapped in a <pre> tag
67
66
*/
68
- public function format (string $ string, bool $ highlight = true ) : string
67
+ public function format (string $ string ) : string
69
68
{
70
69
// This variable will be populated with formatted html
71
70
$ return = '' ;
@@ -99,13 +98,11 @@ public function format(string $string, bool $highlight = true) : string
99
98
100
99
// Format token by token
101
100
foreach ($ indexedTokens as $ i => $ indexedToken ) {
102
- $ token = $ indexedToken ['token ' ];
103
- // Get highlighted token if doing syntax highlighting
104
- if ($ highlight ) {
105
- $ highlighted = $ this ->highlighter ->highlightToken ($ token ->type (), $ token ->value ());
106
- } else { // If returning raw text
107
- $ highlighted = $ token ->value ();
108
- }
101
+ $ token = $ indexedToken ['token ' ];
102
+ $ highlighted = $ this ->highlighter ->highlightToken (
103
+ $ token ->type (),
104
+ $ token ->value ()
105
+ );
109
106
110
107
// If we are increasing the special indent level now
111
108
if ($ increaseSpecialIndent ) {
@@ -247,12 +244,8 @@ public function format(string $string, bool $highlight = true) : string
247
244
// This is an error
248
245
$ indentLevel = 0 ;
249
246
250
- if ($ highlight ) {
251
- $ return .= "\n" . $ this ->highlighter ->highlightError (
252
- $ token ->value ()
253
- );
254
- continue ;
255
- }
247
+ $ return .= $ this ->highlighter ->highlightError ($ token ->value ());
248
+ continue ;
256
249
}
257
250
258
251
// Add a newline before the closing parentheses (if not already added)
@@ -360,18 +353,14 @@ public function format(string $string, bool $highlight = true) : string
360
353
}
361
354
362
355
// If there are unmatched parentheses
363
- if ($ highlight && array_search ('block ' , $ indentTypes ) !== false ) {
364
- $ return .= "\n" . $ this ->highlighter ->highlightError ('WARNING: unclosed parentheses or section ' );
356
+ if (array_search ('block ' , $ indentTypes ) !== false ) {
357
+ $ return .= $ this ->highlighter ->highlightError ('WARNING: unclosed parentheses or section ' );
365
358
}
366
359
367
360
// Replace tab characters with the configuration tab character
368
361
$ return = trim (str_replace ("\t" , $ this ->tab , $ return ));
369
362
370
- if ($ highlight ) {
371
- $ return = $ this ->highlighter ->output ($ return );
372
- }
373
-
374
- return $ return ;
363
+ return $ this ->highlighter ->output ($ return );
375
364
}
376
365
377
366
/**
0 commit comments