From 8663d86e4ae37fef78cf026fce25a5814a5f75e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 6 Jun 2024 11:49:35 +0200 Subject: [PATCH 1/5] Add use statement to bin --- bin/sql-formatter | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/sql-formatter b/bin/sql-formatter index d3079ef..9ff7331 100755 --- a/bin/sql-formatter +++ b/bin/sql-formatter @@ -1,7 +1,9 @@ #!/usr/bin/env php Run this PHP script from the command line to see CLI syntax highlighting and formatting. It supports Unix pipes or command line argument style.

"; echo "
php bin/sql-formatter \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\"testing\\");\"
"; echo "
echo \"SELECT * FROM MyTable WHERE (id>5 AND \\`name\\` LIKE \\"testing\\");\" | php bin/sql-formatter
"; @@ -27,4 +29,4 @@ foreach ($autoloadFiles as $autoloadFile) { } } -echo (new \Doctrine\SqlFormatter\SqlFormatter())->format($sql); +echo (new SqlFormatter())->format($sql); From 2bb4ac7dc6cd27534aa11d88e8434ae5fd177a34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 6 Jun 2024 11:49:56 +0200 Subject: [PATCH 2/5] Unify use statements placement in examples --- examples/cli.php | 10 +++++----- examples/examples.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/cli.php b/examples/cli.php index b924414..1023a30 100644 --- a/examples/cli.php +++ b/examples/cli.php @@ -2,6 +2,11 @@ declare(strict_types=1); +use Doctrine\SqlFormatter\SqlFormatter; +use Doctrine\SqlFormatter\Tokenizer; + +require_once __DIR__ . '/../vendor/autoload.php'; + if (PHP_SAPI !== 'cli') :?>

Run this php script from the command line to see CLI syntax highlighting and @@ -23,11 +28,6 @@ $sql = stream_get_contents($fp); } -require_once __DIR__ . '/../vendor/autoload.php'; - -use Doctrine\SqlFormatter\SqlFormatter; -use Doctrine\SqlFormatter\Tokenizer; - assert($sql !== false); echo (new SqlFormatter())->format($sql); diff --git a/examples/examples.php b/examples/examples.php index f34b55f..3c5c1a2 100644 --- a/examples/examples.php +++ b/examples/examples.php @@ -2,12 +2,12 @@ declare(strict_types=1); -require_once __DIR__ . '/../vendor/autoload.php'; - use Doctrine\SqlFormatter\NullHighlighter; use Doctrine\SqlFormatter\SqlFormatter; use Doctrine\SqlFormatter\Tokenizer; +require_once __DIR__ . '/../vendor/autoload.php'; + $formatter = new SqlFormatter(); // Example statements for formatting and highlighting From 60281fa7cefd4e69f52adbe12887831f0018360a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 7 Jun 2024 08:46:31 +0200 Subject: [PATCH 3/5] "tests/performance.php" file was removed --- phpcs.xml.dist | 1 - 1 file changed, 1 deletion(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index fe9fbb4..d05ca62 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -24,7 +24,6 @@ examples/*.php - tests/performance.php From 5a38ae562d96a65c8e2000da9c848e4e502dd30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 7 Jun 2024 08:51:27 +0200 Subject: [PATCH 4/5] Add bin file to phpcs --- phpcs.xml.dist | 1 + 1 file changed, 1 insertion(+) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index d05ca62..65ce6a3 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -18,6 +18,7 @@ + bin/sql-formatter examples src tests From 218a72a98ac58e4ae41ef356f87a115aec77a864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 4 Jun 2024 01:10:03 +0200 Subject: [PATCH 5/5] Remove historical comments --- src/Tokenizer.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Tokenizer.php b/src/Tokenizer.php index 08c4cb9..b8d6d4c 100644 --- a/src/Tokenizer.php +++ b/src/Tokenizer.php @@ -849,7 +849,6 @@ private function makeRegexFromList(array $values, bool $sorted = false): string /** * Takes a SQL string and breaks it into tokens. - * Each token is an associative array with type and value. * * @param string $string The SQL string */ @@ -881,8 +880,6 @@ public function tokenize(string $string): Cursor * @param string $string The SQL string * @param string $upper The SQL string in upper case * @param Token|null $previous The result of the previous createNextToken() call - * - * @return Token An associative array containing the type and value of the token. */ private function createNextToken(string $string, string $upper, int $offset, Token|null $previous = null): Token {