diff --git a/src/Generator/SqlGenerator.php b/src/Generator/SqlGenerator.php index 1501e3a6e..2a87cbee0 100644 --- a/src/Generator/SqlGenerator.php +++ b/src/Generator/SqlGenerator.php @@ -27,6 +27,8 @@ */ class SqlGenerator { + private SqlFormatter|null $formatter = null; + public function __construct( private readonly Configuration $configuration, private readonly AbstractPlatform $platform, @@ -55,7 +57,7 @@ public function generate( $maxLength = $lineLength - 18 - 8; // max - php code length - indentation if (strlen($query) > $maxLength) { - $query = (new SqlFormatter(new NullHighlighter()))->format($query); + $query = $this->formatQuery($query); } } @@ -84,4 +86,11 @@ public function generate( return implode("\n", $code); } + + private function formatQuery(string $query): string + { + $this->formatter ??= new SqlFormatter(new NullHighlighter()); + + return $this->formatter->format($query); + } }