@@ -722,13 +722,6 @@ final class SqlFormatter
722
722
*/
723
723
public $ tab = ' ' ;
724
724
725
- /**
726
- * This flag tells us if SqlFormatted has been initialized
727
- *
728
- * @var bool
729
- */
730
- private $ init ;
731
-
732
725
// Regular expressions for tokenizing
733
726
734
727
/** @var string */
@@ -766,39 +759,6 @@ final class SqlFormatter
766
759
767
760
public function __construct (?Highlighter $ highlighter = null )
768
761
{
769
- if ($ highlighter === null ) {
770
- $ this ->highlighter = $ this ->isCli () ? new CliHighlighter () : new HtmlHighlighter ();
771
-
772
- return ;
773
- }
774
-
775
- $ this ->highlighter = $ highlighter ;
776
- }
777
-
778
- /**
779
- * Get stats about the token cache
780
- *
781
- * @return mixed[] An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes
782
- */
783
- public function getCacheStats () : array
784
- {
785
- return [
786
- 'hits ' =>$ this ->cacheHits ,
787
- 'misses ' =>$ this ->cacheMisses ,
788
- 'entries ' =>count ($ this ->tokenCache ),
789
- 'size ' =>strlen (serialize ($ this ->tokenCache )),
790
- ];
791
- }
792
-
793
- /**
794
- * Stuff that only needs to be done once. Builds regular expressions and sorts the reserved words.
795
- */
796
- private function init () : void
797
- {
798
- if ($ this ->init ) {
799
- return ;
800
- }
801
-
802
762
// Sort reserved word list from longest word to shortest, 3x faster than usort
803
763
$ reservedMap = array_combine ($ this ->reserved , array_map ('strlen ' , $ this ->reserved ));
804
764
assert ($ reservedMap !== false );
@@ -825,7 +785,28 @@ private function init() : void
825
785
826
786
$ this ->regexFunction = '( ' . implode ('| ' , $ this ->quoteRegex ($ this ->functions )) . ') ' ;
827
787
828
- $ this ->init = true ;
788
+ if ($ highlighter === null ) {
789
+ $ this ->highlighter = $ this ->isCli () ? new CliHighlighter () : new HtmlHighlighter ();
790
+
791
+ return ;
792
+ }
793
+
794
+ $ this ->highlighter = $ highlighter ;
795
+ }
796
+
797
+ /**
798
+ * Get stats about the token cache
799
+ *
800
+ * @return mixed[] An array containing the keys 'hits', 'misses', 'entries', and 'size' in bytes
801
+ */
802
+ public function getCacheStats () : array
803
+ {
804
+ return [
805
+ 'hits ' =>$ this ->cacheHits ,
806
+ 'misses ' =>$ this ->cacheMisses ,
807
+ 'entries ' =>count ($ this ->tokenCache ),
808
+ 'size ' =>strlen (serialize ($ this ->tokenCache )),
809
+ ];
829
810
}
830
811
831
812
/**
@@ -1018,8 +999,6 @@ private function getQuotedString(string $string) : string
1018
999
*/
1019
1000
private function tokenize (string $ string ) : array
1020
1001
{
1021
- $ this ->init ();
1022
-
1023
1002
$ tokens = [];
1024
1003
1025
1004
// Used for debugging if there is an error while tokenizing the string
0 commit comments