diff options
178 files changed, 3057 insertions, 3366 deletions
@@ -9,3 +9,5 @@ coverage.xml *sw[op] phpunit.xml phpcs.xml +/.phpunit.result.cache +phpstan.neon diff --git a/.travis.yml b/.travis.yml index 3f9ad35..adb479c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,49 @@ language: php - -dist: trusty +sudo: false +dist: xenial php: - - 5.4 - - 5.5 - - 5.6 - - 7.0 - 7.1 - 7.2 - 7.3 - 7.4 - - hhvm-3.12 - - hhvm-3.18 - - hhvm-3.24 - - nightly matrix: fast_finish: true allow_failures: - php: nightly include: - - php: 7.2 - env: DOCS=yes - php: 7.1 - env: REQUIRE="phpmyadmin/motranslator:^3.0" - - dist: precise - php: 5.3 - -sudo: false + name: "Coding standard check" + script: vendor/bin/phpcs + - php: 7.1 + name: "PHPStan" + script: vendor/bin/phpstan analyze + - php: 7.1 + name: "phpmyadmin/motranslator" + install: + - composer require "phpmyadmin/motranslator:^3.0" + - composer install --no-interaction + - php: 7.2 + name: "API docs" + install: + - composer global require "sami/sami:^4.0" + - composer install --no-interaction + script: + - $HOME/.composer/vendor/bin/sami.php --no-interaction update ./tools/sami-config.php + - php: nightly + install: + - composer install --no-interaction --ignore-platform-reqs + - php: 7.4 + name: "Backward compatibility check" + install: + - composer require --dev roave/backward-compatibility-check + - composer install --no-interaction + script: + - vendor/bin/roave-backward-compatibility-check install: - - if [ $(php -r "echo PHP_MAJOR_VERSION;") -lt 7 ] ; then sed -i '/sami/D' composer.json ; fi - - if [ -n "$REQUIRE" ] ; then composer require "$REQUIRE" ; fi - - composer install + - composer install --no-interaction after_success: - bash <(curl -s https://codecov.io/bash) @@ -43,5 +53,4 @@ cache: - $HOME/.composer/cache script: - - if [ "$DOCS" != "yes" ] ; then ./vendor/bin/phpunit --configuration phpunit.xml.dist ; fi - - if [ "$DOCS" = "yes" ] ; then ./vendor/bin/sami.php --no-interaction update ./tools/sami-config.php ; fi + - vendor/bin/phpunit --configuration phpunit.xml.dist diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fdddd2..79b48fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,26 @@ * Add support for DROP USER statement (#259) * Fix php error "undefined index" when replacing a non existing clause (#249) +## [5.1.0] - 2019-11-12 + +* Fix for PHP deprecations messages about implode for php 7.4+ (#258) +* Parse CHECK keyword on table definition (#264) +* Parse truncate statement (#221) +* Fix wrong parsing of partitions (#265) + +## [5.0.0] - 2019-05-09 + +* Drop support for PHP 5.3, PHP 5.4, PHP 5.5, PHP 5.6, PHP 7.0 and HHVM +* Enable strict mode on PHP files +* Fix redundant whitespaces in build() outputs (#228) +* Fix incorrect error on DEFAULT keyword in ALTER operation (#229) +* Fix incorrect outputs from Query::getClause (#233) +* Add support for reading an SQL file from stdin +* Fix for missing tokenize-query in Composer's vendor/bin/ directory +* Fix for PHP warnings with an incomplete CASE expression (#241) +* Fix for error message with multiple CALL statements (#223) +* Recognize the question mark character as a parameter (#242) + ## [4.4.0] - 2019-11-12 * Fix for PHP deprecations messages about implode for php 7.4+ (#258) @@ -18,6 +38,8 @@ ## [4.3.2] - 2019-06-03 +Backport fixes from 5.0.0 to QA branch: + * Fix redundant whitespaces in build() outputs (#228) * Fix incorrect error on DEFAULT keyword in ALTER operation (#229) * Fix incorrect outputs from Query::getClause (#233) @@ -56,7 +56,7 @@ cat example.sql | ./vendor/bin/lint-query ### Formatting SQL query ```php -echo PhpMyAdmin\SqlParser\Utils\Formatter::format($query, array('type' => 'html')); +echo PhpMyAdmin\SqlParser\Utils\Formatter::format($query, ['type' => 'html']); ``` ### Discoverying query type diff --git a/bin/highlight-query b/bin/highlight-query index 577e4fb..53d380f 100755 --- a/bin/highlight-query +++ b/bin/highlight-query @@ -1,12 +1,13 @@ #!/usr/bin/env php <?php +declare(strict_types=1); -$files = array( +$files = [ __DIR__ . "/../vendor/autoload.php", __DIR__ . "/../../vendor/autoload.php", __DIR__ . "/../../../autoload.php", "vendor/autoload.php" -); +]; $found = false; foreach ($files as $file) { diff --git a/bin/lint-query b/bin/lint-query index 67e7114..1fe12f2 100755 --- a/bin/lint-query +++ b/bin/lint-query @@ -1,12 +1,13 @@ #!/usr/bin/env php <?php +declare(strict_types=1); -$files = array( +$files = [ __DIR__ . "/../vendor/autoload.php", __DIR__ . "/../../vendor/autoload.php", __DIR__ . "/../../../autoload.php", "vendor/autoload.php" -); +]; $found = false; foreach ($files as $file) { @@ -27,4 +28,3 @@ if (!$found) { $cli = new PhpMyAdmin\SqlParser\Utils\CLI(); exit($cli->runLint()); - diff --git a/bin/tokenize-query b/bin/tokenize-query index f32a4e0..e1a55f6 100755 --- a/bin/tokenize-query +++ b/bin/tokenize-query @@ -1,12 +1,13 @@ #!/usr/bin/env php <?php +declare(strict_types=1); -$files = array( +$files = [ __DIR__ . "/../vendor/autoload.php", __DIR__ . "/../../vendor/autoload.php", __DIR__ . "/../../../autoload.php", "vendor/autoload.php" -); +]; $found = false; foreach ($files as $file) { diff --git a/composer.json b/composer.json index 71fd249..51a13f6 100644 --- a/composer.json +++ b/composer.json @@ -16,14 +16,17 @@ "source": "https://github.com/phpmyadmin/sql-parser" }, "require": { - "php": ">=5.3.0", + "php": "^7.1", "symfony/polyfill-mbstring": "^1.3" }, "require-dev": { - "sami/sami": "^4.0", + "phpmyadmin/coding-standard": "^1.0", + "phpmyadmin/motranslator": "^4.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12.3", + "phpstan/phpstan-phpunit": "^0.12.1", "phpunit/php-code-coverage": "*", - "phpunit/phpunit": "~4.8 || ~5.7 || ~6.5", - "squizlabs/php_codesniffer": "~2.9 || ~3.4" + "phpunit/phpunit": "^7.4 || ^8" }, "conflict": { "phpmyadmin/motranslator": "<3.0" @@ -46,5 +49,8 @@ "psr-4": { "PhpMyAdmin\\SqlParser\\Tests\\": "tests" } + }, + "config":{ + "sort-packages": true } } diff --git a/locale/fa/LC_MESSAGES/sqlparser.mo b/locale/fa/LC_MESSAGES/sqlparser.mo Binary files differindex 131b094..acc1cdb 100644 --- a/locale/fa/LC_MESSAGES/sqlparser.mo +++ b/locale/fa/LC_MESSAGES/sqlparser.mo diff --git a/locale/fa/LC_MESSAGES/sqlparser.po b/locale/fa/LC_MESSAGES/sqlparser.po index f801ac0..543f9a6 100644 --- a/locale/fa/LC_MESSAGES/sqlparser.po +++ b/locale/fa/LC_MESSAGES/sqlparser.po @@ -4,8 +4,8 @@ msgstr "" "Project-Id-Version: SQL parser 0\n" "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n" "POT-Creation-Date: 2017-08-21 12:54+0200\n" -"PO-Revision-Date: 2019-03-25 19:40+0000\n" -"Last-Translator: manssour <nikman360@yahoo.com>\n" +"PO-Revision-Date: 2019-07-15 08:00+0000\n" +"Last-Translator: ReZa ZaRe <rz.zare@gmail.com>\n" "Language-Team: Persian <https://hosted.weblate.org/projects/phpmyadmin/" "sql-parser/fa/>\n" "Language: fa\n" @@ -13,10 +13,9 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 3.6-dev\n" +"X-Generator: Weblate 3.8-dev\n" #: src/Component.php:43 src/Component.php:63 -#, fuzzy msgid "Not implemented yet." msgstr "هنوز پیاده سازی نشده." @@ -32,9 +31,9 @@ msgid "Unrecognized alter operation." msgstr "عملیات غیر قابل تشخیص" #: src/Components/Array2d.php:88 -#, fuzzy, php-format +#, php-format msgid "%1$d values were expected, but found %2$d." -msgstr "%1$d مقادیر انتظار می رود، اما یافت شد %2$d" +msgstr "مقادیر %1$d انتظار می رود، اما %2$d یافت شد." #: src/Components/Array2d.php:111 #, fuzzy diff --git a/locale/ko/LC_MESSAGES/sqlparser.mo b/locale/ko/LC_MESSAGES/sqlparser.mo Binary files differindex c9f39f3..0eefb17 100644 --- a/locale/ko/LC_MESSAGES/sqlparser.mo +++ b/locale/ko/LC_MESSAGES/sqlparser.mo diff --git a/locale/ko/LC_MESSAGES/sqlparser.po b/locale/ko/LC_MESSAGES/sqlparser.po index f3eba6d..f133ffe 100644 --- a/locale/ko/LC_MESSAGES/sqlparser.po +++ b/locale/ko/LC_MESSAGES/sqlparser.po @@ -4,16 +4,16 @@ msgstr "" "Project-Id-Version: SQL parser 0\n" "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n" "POT-Creation-Date: 2017-08-21 12:54+0200\n" -"PO-Revision-Date: 2016-12-25 22:02+0000\n" -"Last-Translator: SD SkyKlouD <koongchi135@gmail.com>\n" -"Language-Team: Korean <https://hosted.weblate.org/projects/phpmyadmin/sql-" -"parser/ko/>\n" +"PO-Revision-Date: 2019-10-06 06:56+0000\n" +"Last-Translator: Yoonseo Kim <yyumz6961@gmail.com>\n" +"Language-Team: Korean <https://hosted.weblate.org/projects/phpmyadmin/" +"sql-parser/ko/>\n" "Language: ko\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 2.11-dev\n" +"X-Generator: Weblate 3.9-dev\n" #: src/Component.php:43 src/Component.php:63 msgid "Not implemented yet." @@ -22,7 +22,7 @@ msgstr "아직 구현되지 않은 기능입니다." #: src/Components/AlterOperation.php:241 src/Statement.php:334 msgid "" "A new statement was found, but no delimiter between it and the previous one." -msgstr "" +msgstr "새로운 문장이 발견되었지만, 이전 문장과의 구분기호가 없습니다." #: src/Components/AlterOperation.php:253 msgid "Unrecognized alter operation." @@ -35,11 +35,11 @@ msgstr "값 %1$d 이 예상되었지만, %2$d 가 발견되었습니다." #: src/Components/Array2d.php:111 msgid "An opening bracket followed by a set of values was expected." -msgstr "" +msgstr "일련의 값들에 의해 여는 괄호('(')가 예상됩니다." #: src/Components/ArrayObj.php:114 src/Components/CreateDefinition.php:201 msgid "An opening bracket was expected." -msgstr "" +msgstr "여는 괄호가 예상됩니다." #: src/Components/CaseExpression.php:135 src/Components/CaseExpression.php:164 #: src/Components/CaseExpression.php:176 src/Components/CaseExpression.php:190 @@ -64,36 +64,32 @@ msgstr "예상되지 않은 CASE 문의 종료" msgid "" "A symbol name was expected! A reserved keyword can not be used as a column " "name without backquotes." -msgstr "" +msgstr "상징적인 이름이 예상되었습니다! 예약어는 큰 따옴표 없이 열 이름으로 사용될 수 없습니다." #: src/Components/CreateDefinition.php:237 msgid "A symbol name was expected!" msgstr "심볼 이름이 예상되었습니다!" #: src/Components/CreateDefinition.php:270 -#, fuzzy -#| msgid "No tables selected." msgid "A comma or a closing bracket was expected." -msgstr "테이블이 선택되지 않았습니다." +msgstr "쉼표 또는 닫는 괄호가 예상됩니다." #: src/Components/CreateDefinition.php:286 msgid "A closing bracket was expected." -msgstr "" +msgstr "닫는 괄호가 예상됩니다." #: src/Components/DataType.php:123 msgid "Unrecognized data type." msgstr "인식할 수 없는 데이터 형식입니다." #: src/Components/Expression.php:244 src/Components/Expression.php:394 -#, fuzzy -#| msgid "No tables selected." msgid "An alias was expected." -msgstr "테이블이 선택되지 않았습니다." +msgstr "가명(별칭)이 예상됩니다." #: src/Components/Expression.php:332 src/Components/Expression.php:351 #: src/Components/Expression.php:383 msgid "An alias was previously found." -msgstr "" +msgstr "가명(별칭) 이전에 발견되었습니다." #: src/Components/Expression.php:364 msgid "Unexpected dot." @@ -125,56 +121,45 @@ msgid "The new name of the table was expected." msgstr "테이블의 새로운 이름이 예상되었습니다." #: src/Components/RenameOperation.php:153 -#, fuzzy -#| msgid "The row has been deleted." msgid "A rename operation was expected." -msgstr "행을 삭제 하였습니다." +msgstr "이름 바꾸기 작업이 예상되었습니다." #: src/Components/SetOperation.php:117 -#, fuzzy -#| msgid "as regular expression" msgid "Missing expression." -msgstr "정규표현식" +msgstr "누락된 표현입니다." #: src/Lexer.php:237 -#, fuzzy -#| msgid "Unexpected characters on line %s." msgid "Unexpected character." -msgstr "%s 라인에 알 수 없는 문자가 있습니다." +msgstr "예상치 못한 문자입니다." #: src/Lexer.php:278 msgid "Expected whitespace(s) before delimiter." -msgstr "" +msgstr "구분기호 앞에 공백이 필요합니다." #: src/Lexer.php:296 src/Lexer.php:314 msgid "Expected delimiter." -msgstr "" +msgstr "구분기호가 필요합니다." #: src/Lexer.php:843 -#, fuzzy, php-format -#| msgid "Event %1$s has been created." +#, php-format msgid "Ending quote %1$s was expected." -msgstr "이벤트 %1$s 를 생성했습니다." +msgstr "종료 견적 %1$s 가 예상됩니다." #: src/Lexer.php:884 -#, fuzzy -#| msgid "Table name template" msgid "Variable name was expected." -msgstr "파일명 템플릿" +msgstr "변수명이 필요합니다." #: src/Parser.php:423 -#, fuzzy -#| msgid "At Beginning of Table" msgid "Unexpected beginning of statement." -msgstr "테이블의 처음" +msgstr "예상치 못한 명령문의 시작입니다." #: src/Parser.php:442 msgid "Unrecognized statement type." -msgstr "" +msgstr "인식할 수 없는 명령문 유형입니다." #: src/Parser.php:527 msgid "No transaction was previously started." -msgstr "" +msgstr "이전에 시작된 처리가 없습니다." #: src/Statement.php:242 src/Statements/DeleteStatement.php:254 #: src/Statements/DeleteStatement.php:306 @@ -182,65 +167,49 @@ msgstr "" #: src/Statements/InsertStatement.php:246 src/Statements/LoadStatement.php:261 #: src/Statements/LoadStatement.php:291 src/Statements/LoadStatement.php:310 #: src/Statements/ReplaceStatement.php:190 -#, fuzzy -#| msgid "Unexpected characters on line %s." msgid "Unexpected token." -msgstr "%s 라인에 알 수 없는 문자가 있습니다." +msgstr "예상치 못한 표현(토큰)입니다." #: src/Statement.php:306 msgid "This type of clause was previously parsed." -msgstr "" +msgstr "이 유형의 절은 이전에 구문 분석되었습니다." #: src/Statement.php:366 msgid "Unrecognized keyword." -msgstr "" +msgstr "인식할 수 없는 키워드입니다." #: src/Statement.php:377 -#, fuzzy -#| msgid "At Beginning of Table" msgid "Keyword at end of statement." -msgstr "테이블의 처음" +msgstr "명령문 끝에 있는 키워드." #: src/Statement.php:503 -#, fuzzy -#| msgid "At Beginning of Table" msgid "Unexpected ordering of clauses." -msgstr "테이블의 처음" +msgstr "예기치 못한 문장(절) 순서." #: src/Statements/CreateStatement.php:375 -#, fuzzy -#| msgid "The number of tables that are open." msgid "The name of the entity was expected." -msgstr "열린 테이블 수." +msgstr "개체의 이름으로 예상됩니다." #: src/Statements/CreateStatement.php:430 -#, fuzzy -#| msgid "Table name template" msgid "A table name was expected." -msgstr "파일명 템플릿" +msgstr "테이블 이름으로 예상됩니다." #: src/Statements/CreateStatement.php:438 -#, fuzzy -#| msgid "The row has been deleted." msgid "At least one column definition was expected." -msgstr "행을 삭제 하였습니다." +msgstr "최소한 하나의 열 정의가 예상됩니다." #: src/Statements/CreateStatement.php:550 msgid "A \"RETURNS\" keyword was expected." -msgstr "" +msgstr "\"RETURNS\"키워드가 필요합니다." #: src/Statements/DeleteStatement.php:314 msgid "This type of clause is not valid in Multi-table queries." -msgstr "" +msgstr "이 유형의 문장(절)은 다중테이블 쿼리에서 유효하지 않습니다." #: tests/Lexer/LexerTest.php:19 tests/Parser/ParserTest.php:58 -#, fuzzy -#| msgid "Error" msgid "error #1" -msgstr "오류" +msgstr "오류 #1" #: tests/Lexer/LexerTest.php:46 tests/Parser/ParserTest.php:80 -#, fuzzy -#| msgid "Gather errors" msgid "strict error" -msgstr "오류 수집" +msgstr "엄격한 오류" diff --git a/locale/nb/LC_MESSAGES/sqlparser.mo b/locale/nb/LC_MESSAGES/sqlparser.mo Binary files differindex de94a72..ec0c1c6 100644 --- a/locale/nb/LC_MESSAGES/sqlparser.mo +++ b/locale/nb/LC_MESSAGES/sqlparser.mo diff --git a/locale/nb/LC_MESSAGES/sqlparser.po b/locale/nb/LC_MESSAGES/sqlparser.po index 133b1f7..e49c962 100644 --- a/locale/nb/LC_MESSAGES/sqlparser.po +++ b/locale/nb/LC_MESSAGES/sqlparser.po @@ -4,7 +4,7 @@ msgstr "" "Project-Id-Version: SQL parser 0\n" "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n" "POT-Creation-Date: 2017-08-21 12:54+0200\n" -"PO-Revision-Date: 2019-04-30 14:36+0000\n" +"PO-Revision-Date: 2019-08-18 18:22+0000\n" "Last-Translator: Allan Nordhøy <epost@anotheragency.no>\n" "Language-Team: Norwegian Bokmål <https://hosted.weblate.org/projects/" "phpmyadmin/sql-parser/nb_NO/>\n" @@ -13,7 +13,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 3.6.1\n" +"X-Generator: Weblate 3.8\n" #: src/Component.php:43 src/Component.php:63 msgid "Not implemented yet." @@ -35,14 +35,12 @@ msgid "%1$d values were expected, but found %2$d." msgstr "%1$d verdier var forventet, men fant %2$d." #: src/Components/Array2d.php:111 -#, fuzzy msgid "An opening bracket followed by a set of values was expected." -msgstr "En åpeningsklamme etterfulgt av ett sett verdier var forventet." +msgstr "Åpeningsklamme etterfulgt av ett sett verdier forventet." #: src/Components/ArrayObj.php:114 src/Components/CreateDefinition.php:201 -#, fuzzy msgid "An opening bracket was expected." -msgstr "En åpningsklamme var forventet." +msgstr "Åpningsklamme forventet." #: src/Components/CaseExpression.php:135 src/Components/CaseExpression.php:164 #: src/Components/CaseExpression.php:176 src/Components/CaseExpression.php:190 @@ -76,10 +74,8 @@ msgid "A symbol name was expected!" msgstr "Symbolnavn forventet!" #: src/Components/CreateDefinition.php:270 -#, fuzzy -#| msgid "No tables selected." msgid "A comma or a closing bracket was expected." -msgstr "Et komma eller lukkingsklamme var forventet." +msgstr "Komma eller lukkingsklamme forventet." #: src/Components/CreateDefinition.php:286 msgid "A closing bracket was expected." @@ -202,7 +198,6 @@ msgid "A table name was expected." msgstr "Tabellnavn forventet." #: src/Statements/CreateStatement.php:438 -#, fuzzy msgid "At least one column definition was expected." msgstr "Minst én kolonnedefinisjon forventet." diff --git a/locale/th/LC_MESSAGES/sqlparser.mo b/locale/th/LC_MESSAGES/sqlparser.mo Binary files differindex 42a74f8..0e1293c 100644 --- a/locale/th/LC_MESSAGES/sqlparser.mo +++ b/locale/th/LC_MESSAGES/sqlparser.mo diff --git a/locale/th/LC_MESSAGES/sqlparser.po b/locale/th/LC_MESSAGES/sqlparser.po index 85c441b..df6e50f 100644 --- a/locale/th/LC_MESSAGES/sqlparser.po +++ b/locale/th/LC_MESSAGES/sqlparser.po @@ -4,8 +4,8 @@ msgstr "" "Project-Id-Version: SQL parser 0\n" "Report-Msgid-Bugs-To: translators@phpmyadmin.net\n" "POT-Creation-Date: 2017-08-21 12:54+0200\n" -"PO-Revision-Date: 2018-08-17 10:42+0000\n" -"Last-Translator: Anusuk Sangubon <jaideejung007@gmail.com>\n" +"PO-Revision-Date: 2019-07-19 00:04+0000\n" +"Last-Translator: Kongfa Warorot <gongpha@hotmail.com>\n" "Language-Team: Thai <https://hosted.weblate.org/projects/phpmyadmin/" "sql-parser/th/>\n" "Language: th\n" @@ -13,7 +13,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 3.2-dev\n" +"X-Generator: Weblate 3.8-dev\n" #: src/Component.php:43 src/Component.php:63 msgid "Not implemented yet." @@ -170,59 +170,48 @@ msgstr "ไม่มีข้อมูลเข้าออกได้เริ #: src/Statements/LoadStatement.php:291 src/Statements/LoadStatement.php:310 #: src/Statements/ReplaceStatement.php:190 msgid "Unexpected token." -msgstr "" +msgstr "โทเค็นที่ไม่ได้คาดหวังไว้" #: src/Statement.php:306 msgid "This type of clause was previously parsed." -msgstr "" +msgstr "ชนิดของประโยคนี้ถูกวิเคราะห์มาแล้วก่อนหน้านี้" #: src/Statement.php:366 msgid "Unrecognized keyword." -msgstr "" +msgstr "ไม่รู้จักชนิดของคีย์เวิร์ด" #: src/Statement.php:377 -#, fuzzy -#| msgid "Unexpected beginning of statement." msgid "Keyword at end of statement." -msgstr "ไม่อาจคาดเดาจุดเริ่มต้นของประพจน์" +msgstr "คีย์เวิร์ดในตอนท้ายของคำสั่ง" #: src/Statement.php:503 -#, fuzzy -#| msgid "At Beginning of Table" msgid "Unexpected ordering of clauses." -msgstr "ที่จุดเริ่มต้นของตาราง" +msgstr "การเรียงของประโยคที่ไม่ได้คาดหวังไว้" #: src/Statements/CreateStatement.php:375 msgid "The name of the entity was expected." -msgstr "" +msgstr "ชื่อเอนทิติได้รับการคาดหวัง" #: src/Statements/CreateStatement.php:430 -#, fuzzy msgid "A table name was expected." -msgstr "รูปแบบของชื่อไฟล์" +msgstr "ชื่อตารางได้รับการคาดหวัง" #: src/Statements/CreateStatement.php:438 -#, fuzzy -#| msgid "The row has been deleted." msgid "At least one column definition was expected." -msgstr "ลบเรียบร้อยแล้ว" +msgstr "การกำหนดคอลัมน์อย่างน้อยหนึ่งคอลัมน์ได้รับการคาดหวัง" #: src/Statements/CreateStatement.php:550 msgid "A \"RETURNS\" keyword was expected." -msgstr "" +msgstr "คีย์เวิร์ด \"RETURNS\" ได้รับการคาดหวัง" #: src/Statements/DeleteStatement.php:314 msgid "This type of clause is not valid in Multi-table queries." -msgstr "" +msgstr "ประโยคชนิดนี้ไม่ถูกต้องในการเรียกใช้แบบหลายตาราง" #: tests/Lexer/LexerTest.php:19 tests/Parser/ParserTest.php:58 -#, fuzzy -#| msgid "Error" msgid "error #1" -msgstr "ผิดพลาด" +msgstr "ผิดพลาด #1" #: tests/Lexer/LexerTest.php:46 tests/Parser/ParserTest.php:80 -#, fuzzy -#| msgid "Gather errors" msgid "strict error" -msgstr "รวบรวมข้อผิดพลาด" +msgstr "ข้อผิดพลาดที่ครัดเคร้ง" diff --git a/phpcs.xml.dist b/phpcs.xml.dist index b823709..81b5c0c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -4,6 +4,12 @@ name="phpMyAdmin" xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd" > + <rule ref="./vendor/phpmyadmin/coding-standard/PhpMyAdmin/ruleset.xml"> + <exclude name="PEAR.Commenting.FileComment"/> + <exclude name="PEAR.Commenting.ClassComment"/> + <exclude name="PEAR.Commenting.FunctionComment"/> + </rule> + <rule ref="Squiz.Arrays.ArrayDeclaration.IndexNoNewline"> <exclude-pattern>*/src/Contexts/*</exclude-pattern> </rule> @@ -20,36 +26,6 @@ <rule ref="Squiz.NamingConventions.ValidVariableName"> <severity>4</severity> </rule> - <rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned"> - <severity>0</severity> - </rule> - <rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned"> - <severity>0</severity> - </rule> - <rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned"> - <severity>0</severity> - </rule> - <rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"> - <severity>0</severity> - </rule> - <rule ref="Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps"> - <severity>0</severity> - </rule> - <rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast"> - <severity>0</severity> - </rule> - <rule ref="Generic.Files.LineLength.MaxExceeded"> - <severity>0</severity> - </rule> - <rule ref="Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed"> - <severity>0</severity> - </rule> - <rule ref="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed"> - <severity>0</severity> - </rule> - <rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"> - <severity>0</severity> - </rule> <arg value="sp"/> <arg name="colors"/> diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..9fc98c0 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,10 @@ +parameters: + level: 2 + paths: + - src + - tests + - bin + reportUnmatchedIgnoredErrors: true + inferPrivatePropertyTypeFromConstructor: true + ignoreErrors: + - '#Unsafe usage of new static\(\)\.#' diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d96b96d..36faf50 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,8 +9,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" - syntaxCheck="false"> + stopOnFailure="false"> <logging> <log type="coverage-clover" target="coverage.xml" /> </logging> diff --git a/src/Component.php b/src/Component.php index bb230c2..656d318 100644 --- a/src/Component.php +++ b/src/Component.php @@ -1,5 +1,4 @@ <?php - /** * Defines a component that is later extended to parse specialized components or * keywords. @@ -8,16 +7,15 @@ * *Component parsers can be reused in multiple situations and *Keyword parsers * count on the *Component classes to do their job. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; +use Exception; + /** * A component (of a statement) is a part of a statement that is common to * multiple query types. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ abstract class Component { @@ -29,18 +27,18 @@ abstract class Component * @param TokensList $list the list of tokens that are being parsed * @param array $options parameters for parsing * - * @throws \Exception not implemented yet - * * @return mixed + * + * @throws Exception not implemented yet. */ public static function parse( Parser $parser, TokensList $list, - array $options = array() + array $options = [] ) { // This method should be abstract, but it can't be both static and // abstract. - throw new \Exception(Translator::gettext('Not implemented yet.')); + throw new Exception(Translator::gettext('Not implemented yet.')); } /** @@ -52,15 +50,15 @@ abstract class Component * @param mixed $component the component to be built * @param array $options parameters for building * - * @throws \Exception not implemented yet + * @return mixed * - * @return string + * @throws Exception not implemented yet. */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { // This method should be abstract, but it can't be both static and // abstract. - throw new \Exception(Translator::gettext('Not implemented yet.')); + throw new Exception(Translator::gettext('Not implemented yet.')); } /** diff --git a/src/Components/AlterOperation.php b/src/Components/AlterOperation.php index e3a3f9f..09f928f 100644 --- a/src/Components/AlterOperation.php +++ b/src/Components/AlterOperation.php @@ -1,8 +1,8 @@ <?php - /** * Parses an alter operation. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses an alter operation. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class AlterOperation extends Component { @@ -25,67 +21,67 @@ class AlterOperation extends Component * * @var array */ - public static $DB_OPTIONS = array( - 'CHARACTER SET' => array( + public static $DB_OPTIONS = [ + 'CHARACTER SET' => [ 1, - 'var' - ), - 'CHARSET' => array( + 'var', + ], + 'CHARSET' => [ 1, - 'var' - ), - 'DEFAULT CHARACTER SET' => array( + 'var', + ], + 'DEFAULT CHARACTER SET' => [ 1, - 'var' - ), - 'DEFAULT CHARSET' => array( + 'var', + ], + 'DEFAULT CHARSET' => [ 1, - 'var' - ), - 'UPGRADE' => array( + 'var', + ], + 'UPGRADE' => [ 1, - 'var' - ), - 'COLLATE' => array( + 'var', + ], + 'COLLATE' => [ 2, - 'var' - ), - 'DEFAULT COLLATE' => array( + 'var', + ], + 'DEFAULT COLLATE' => [ 2, - 'var' - ) - ); + 'var', + ], + ]; /** * All table options. * * @var array */ - public static $TABLE_OPTIONS = array( - 'ENGINE' => array( + public static $TABLE_OPTIONS = [ + 'ENGINE' => [ 1, - 'var=' - ), - 'AUTO_INCREMENT' => array( + 'var=', + ], + 'AUTO_INCREMENT' => [ 1, - 'var=' - ), - 'AVG_ROW_LENGTH' => array( + 'var=', + ], + 'AVG_ROW_LENGTH' => [ 1, - 'var' - ), - 'MAX_ROWS' => array( + 'var', + ], + 'MAX_ROWS' => [ 1, - 'var' - ), - 'ROW_FORMAT' => array( + 'var', + ], + 'ROW_FORMAT' => [ 1, - 'var' - ), - 'COMMENT' => array( + 'var', + ], + 'COMMENT' => [ 1, - 'var' - ), + 'var', + ], 'ADD' => 1, 'ALTER' => 1, 'ANALYZE' => 1, @@ -122,17 +118,17 @@ class AlterOperation extends Component 'PRIMARY KEY' => 2, 'SPATIAL' => 2, 'TABLESPACE' => 2, - 'INDEX' => 2 - ); + 'INDEX' => 2, + ]; /** * All view options. * * @var array */ - public static $VIEW_OPTIONS = array( + public static $VIEW_OPTIONS = [ 'AS' => 1, - ); + ]; /** * Options of this operation. @@ -153,11 +149,9 @@ class AlterOperation extends Component * * @var Token[]|string */ - public $unknown = array(); + public $unknown = []; /** - * Constructor. - * * @param OptionsArray $options options of alter operation * @param Expression $field altered field * @param array $unknown unparsed tokens found at the end of operation @@ -165,7 +159,7 @@ class AlterOperation extends Component public function __construct( $options = null, $field = null, - $unknown = array() + $unknown = [] ) { $this->options = $options; $this->field = $field; @@ -179,9 +173,9 @@ class AlterOperation extends Component * * @return AlterOperation */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * Counts brackets. @@ -251,10 +245,10 @@ class AlterOperation extends Component $ret->field = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, - 'parseField' => 'column' - ) + 'parseField' => 'column', + ] ); if ($ret->field === null) { // No field was read. We go back one token so the next @@ -315,10 +309,10 @@ class AlterOperation extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { $ret = $component->options . ' '; - if ((isset($component->field)) && ($component->field !== '')) { + if (isset($component->field) && ($component->field !== '')) { $ret .= $component->field . ' '; } $ret .= TokensList::build($component->unknown); @@ -331,11 +325,12 @@ class AlterOperation extends Component * between column and table alteration * * @param string $tokenValue Value of current token + * * @return bool */ private static function checkIfColumnDefinitionKeyword($tokenValue) { - $common_options = array( + $common_options = [ 'AUTO_INCREMENT', 'COMMENT', 'DEFAULT', @@ -344,8 +339,8 @@ class AlterOperation extends Component 'PRIMARY', 'UNIQUE', 'PRIMARY KEY', - 'UNIQUE KEY' - ); + 'UNIQUE KEY', + ]; // Since these options can be used for // both table as well as a specific column in the table return in_array($tokenValue, $common_options); diff --git a/src/Components/Array2d.php b/src/Components/Array2d.php index 984179c..1ae5c30 100644 --- a/src/Components/Array2d.php +++ b/src/Components/Array2d.php @@ -1,8 +1,8 @@ <?php - /** * `VALUES` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Translator; /** * `VALUES` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Array2d extends Component { @@ -28,9 +24,9 @@ class Array2d extends Component * * @return ArrayObj[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; /** * The number of values in each set. @@ -124,7 +120,7 @@ class Array2d extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { return ArrayObj::build($component); } diff --git a/src/Components/ArrayObj.php b/src/Components/ArrayObj.php index 2b2fe92..ab1ad61 100644 --- a/src/Components/ArrayObj.php +++ b/src/Components/ArrayObj.php @@ -1,8 +1,8 @@ <?php - /** * Parses an array. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses an array. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ArrayObj extends Component { @@ -25,22 +21,20 @@ class ArrayObj extends Component * * @var array */ - public $raw = array(); + public $raw = []; /** * The array that contains the processed value of each token. * * @var array */ - public $values = array(); + public $values = []; /** - * Constructor. - * * @param array $raw the unprocessed values * @param array $values the processed values */ - public function __construct(array $raw = array(), array $values = array()) + public function __construct(array $raw = [], array $values = []) { $this->raw = $raw; $this->values = $values; @@ -53,9 +47,9 @@ class ArrayObj extends Component * * @return ArrayObj|Component[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = empty($options['type']) ? new self() : array(); + $ret = empty($options['type']) ? new static() : []; /** * The last raw expression. @@ -144,7 +138,7 @@ class ArrayObj extends Component $ret[] = $options['type']::parse( $parser, $list, - empty($options['typeOptions']) ? array() : $options['typeOptions'] + empty($options['typeOptions']) ? [] : $options['typeOptions'] ); } } @@ -153,14 +147,13 @@ class ArrayObj extends Component // // This is treated differently to treat the following cases: // - // => array() - // (,) => array('', '') - // () => array() - // (a,) => array('a', '') - // (a) => array('a') - // + // => [] + // [,] => ['', ''] + // [] => [] + // [a,] => ['a', ''] + // [a] => ['a'] $lastRaw = trim($lastRaw); - if ((empty($options['type'])) + if (empty($options['type']) && ((strlen($lastRaw) > 0) || ($isCommaLast)) ) { $ret->raw[] = $lastRaw; @@ -176,7 +169,7 @@ class ArrayObj extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/CaseExpression.php b/src/Components/CaseExpression.php index f6b422c..26c044f 100644 --- a/src/Components/CaseExpression.php +++ b/src/Components/CaseExpression.php @@ -1,8 +1,8 @@ <?php - /** * Parses a reference to a CASE expression. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a reference to a CASE expression. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CaseExpression extends Component { @@ -33,21 +29,21 @@ class CaseExpression extends Component * * @var array */ - public $conditions = array(); + public $conditions = []; /** * The results matching with the WHEN clauses. * * @var array */ - public $results = array(); + public $results = []; /** * The values to be compared against. * * @var array */ - public $compare_values = array(); + public $compare_values = []; /** * The result in ELSE section of expr. @@ -70,9 +66,6 @@ class CaseExpression extends Component */ public $expr = ''; - /** - * Constructor. - */ public function __construct() { } @@ -84,9 +77,9 @@ class CaseExpression extends Component * * @return CaseExpression */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * State of parser. @@ -279,7 +272,7 @@ class CaseExpression extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { $ret = 'CASE '; if (isset($component->value)) { diff --git a/src/Components/Condition.php b/src/Components/Condition.php index 700b071..b719b28 100644 --- a/src/Components/Condition.php +++ b/src/Components/Condition.php @@ -1,8 +1,8 @@ <?php - /** * `WHERE` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `WHERE` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Condition extends Component { @@ -25,20 +21,20 @@ class Condition extends Component * * @var array */ - public static $DELIMITERS = array( + public static $DELIMITERS = [ '&&', '||', 'AND', 'OR', - 'XOR' - ); + 'XOR', + ]; /** * List of allowed reserved keywords in conditions. * * @var array */ - public static $ALLOWED_KEYWORDS = array( + public static $ALLOWED_KEYWORDS = [ 'ALL' => 1, 'AND' => 1, 'BETWEEN' => 1, @@ -56,15 +52,15 @@ class Condition extends Component 'OR' => 1, 'REGEXP' => 1, 'RLIKE' => 1, - 'XOR' => 1 - ); + 'XOR' => 1, + ]; /** * Identifiers recognized. * * @var array */ - public $identifiers = array(); + public $identifiers = []; /** * Whether this component is an operator. @@ -81,13 +77,11 @@ class Condition extends Component public $expr; /** - * Constructor. - * * @param string $expr the condition or the operator */ public function __construct($expr = null) { - $this->expr = trim($expr); + $this->expr = trim((string) $expr); } /** @@ -97,11 +91,11 @@ class Condition extends Component * * @return Condition[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; - $expr = new self(); + $expr = new static(); /** * Counts brackets. @@ -159,12 +153,12 @@ class Condition extends Component } // Adding the operator. - $expr = new self($token->value); + $expr = new static($token->value); $expr->isOperator = true; $ret[] = $expr; // Preparing to parse another condition. - $expr = new self(); + $expr = new static(); continue; } } @@ -222,7 +216,7 @@ class Condition extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(' ', $component); diff --git a/src/Components/CreateDefinition.php b/src/Components/CreateDefinition.php index 0f44e09..0cd29c9 100644 --- a/src/Components/CreateDefinition.php +++ b/src/Components/CreateDefinition.php @@ -1,10 +1,10 @@ <?php - /** * Parses the create definition of a column or a key. * * Used for parsing `CREATE TABLE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -18,10 +18,6 @@ use PhpMyAdmin\SqlParser\TokensList; * Parses the create definition of a column or a key. * * Used for parsing `CREATE TABLE` statement. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CreateDefinition extends Component { @@ -30,61 +26,61 @@ class CreateDefinition extends Component * * @var array */ - public static $FIELD_OPTIONS = array( + public static $FIELD_OPTIONS = [ // Tells the `OptionsArray` to not sort the options. // See the note below. '_UNSORTED' => true, 'NOT NULL' => 1, 'NULL' => 1, - 'DEFAULT' => array( + 'DEFAULT' => [ 2, 'expr', - array('breakOnAlias' => true) - ), + ['breakOnAlias' => true], + ], /* Following are not according to grammar, but MySQL happily accepts * these at any location */ - 'CHARSET' => array( + 'CHARSET' => [ 2, 'var', - ), - 'COLLATE' => array( + ], + 'COLLATE' => [ 3, 'var', - ), + ], 'AUTO_INCREMENT' => 3, 'PRIMARY' => 4, 'PRIMARY KEY' => 4, 'UNIQUE' => 4, 'UNIQUE KEY' => 4, - 'COMMENT' => array( + 'COMMENT' => [ 5, 'var', - ), - 'COLUMN_FORMAT' => array( + ], + 'COLUMN_FORMAT' => [ 6, 'var', - ), - 'ON UPDATE' => array( + ], + 'ON UPDATE' => [ 7, 'expr', - ), + ], // Generated columns options. 'GENERATED ALWAYS' => 8, - 'AS' => array( + 'AS' => [ 9, 'expr', - array('parenthesesDelimited' => true) - ), + ['parenthesesDelimited' => true], + ], 'VIRTUAL' => 10, 'PERSISTENT' => 11, 'STORED' => 11, - 'CHECK' => array( + 'CHECK' => [ 12, 'expr', - array('parenthesesDelimited' => true), - ) + ['parenthesesDelimited' => true], + ], // Common entries. // // NOTE: Some of the common options are not in the same order which @@ -94,12 +90,12 @@ class CreateDefinition extends Component // // 'UNIQUE' => 4, // 'UNIQUE KEY' => 4, - // 'COMMENT' => array(5, 'var'), + // 'COMMENT' => [5, 'var'], // 'NOT NULL' => 1, // 'NULL' => 1, // 'PRIMARY' => 4, // 'PRIMARY KEY' => 4, - ); + ]; /** * The name of the new column. @@ -144,8 +140,6 @@ class CreateDefinition extends Component public $options; /** - * Constructor. - * * @param string $name the name of the field * @param OptionsArray $options the options of this field * @param DataType|Key $type the data type of this field or the key @@ -177,11 +171,11 @@ class CreateDefinition extends Component * * @return CreateDefinition[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; - $expr = new self(); + $expr = new static(); /** * The state of the parser. @@ -290,7 +284,7 @@ class CreateDefinition extends Component if (! empty($expr->type) || ! empty($expr->key)) { $ret[] = $expr; } - $expr = new self(); + $expr = new static(); if ($token->value === ',') { $state = 1; } elseif ($token->value === ')') { @@ -331,7 +325,7 @@ class CreateDefinition extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return "(\n " . implode(",\n ", $component) . "\n)"; @@ -350,7 +344,7 @@ class CreateDefinition extends Component if (! empty($component->type)) { $tmp .= DataType::build( $component->type, - array('lowercase' => true) + ['lowercase' => true] ) . ' '; } diff --git a/src/Components/DataType.php b/src/Components/DataType.php index d19d434..484e559 100644 --- a/src/Components/DataType.php +++ b/src/Components/DataType.php @@ -1,8 +1,8 @@ <?php - /** * Parses a data type. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a data type. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class DataType extends Component { @@ -25,23 +21,23 @@ class DataType extends Component * * @var array */ - public static $DATA_TYPE_OPTIONS = array( + public static $DATA_TYPE_OPTIONS = [ 'BINARY' => 1, - 'CHARACTER SET' => array( + 'CHARACTER SET' => [ 2, 'var', - ), - 'CHARSET' => array( + ], + 'CHARSET' => [ 2, 'var', - ), - 'COLLATE' => array( + ], + 'COLLATE' => [ 3, 'var', - ), + ], 'UNSIGNED' => 4, - 'ZEROFILL' => 5 - ); + 'ZEROFILL' => 5, + ]; /** * The name of the data type. @@ -63,7 +59,7 @@ class DataType extends Component * * @var array */ - public $parameters = array(); + public $parameters = []; /** * The options of this data type. @@ -73,15 +69,13 @@ class DataType extends Component public $options; /** - * Constructor. - * * @param string $name the name of this data type * @param array $parameters the parameters (size or possible values) * @param OptionsArray $options the options of this data type */ public function __construct( $name = null, - array $parameters = array(), + array $parameters = [], $options = null ) { $this->name = $name; @@ -96,9 +90,9 @@ class DataType extends Component * * @return DataType|null */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * The state of the parser. @@ -127,7 +121,7 @@ class DataType extends Component } if ($state === 0) { - $ret->name = strtoupper($token->value); + $ret->name = strtoupper((string) $token->value); if (($token->type !== Token::TYPE_KEYWORD) || (! ($token->flags & Token::FLAG_KEYWORD_DATA_TYPE))) { $parser->error('Unrecognized data type.', $token); } @@ -136,7 +130,7 @@ class DataType extends Component if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) { $parameters = ArrayObj::parse($parser, $list); ++$list->idx; - $ret->parameters = (($ret->name === 'ENUM') || ($ret->name === 'SET')) ? + $ret->parameters = ($ret->name === 'ENUM') || ($ret->name === 'SET') ? $parameters->raw : $parameters->values; } $ret->options = OptionsArray::parse($parser, $list, static::$DATA_TYPE_OPTIONS); @@ -160,7 +154,7 @@ class DataType extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { $name = empty($options['lowercase']) ? $component->name : strtolower($component->name); diff --git a/src/Components/Expression.php b/src/Components/Expression.php index 2cf119b..bf97937 100644 --- a/src/Components/Expression.php +++ b/src/Components/Expression.php @@ -1,9 +1,9 @@ <?php - /** * Parses a reference to an expression (column, table or database name, function * call, mathematical expression, etc.). */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -16,10 +16,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a reference to an expression (column, table or database name, function * call, mathematical expression, etc.). - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Expression extends Component { @@ -28,7 +24,7 @@ class Expression extends Component * * @var array */ - private static $ALLOWED_KEYWORDS = array( + private static $ALLOWED_KEYWORDS = [ 'AS' => 1, 'DUAL' => 1, 'NULL' => 1, @@ -39,8 +35,8 @@ class Expression extends Component 'OR' => 1, 'XOR' => 1, 'NOT' => 1, - 'MOD' => 1 - ); + 'MOD' => 1, + ]; /** * The name of this database. @@ -92,8 +88,6 @@ class Expression extends Component public $subquery; /** - * Constructor. - * * Syntax: * new Expression('expr') * new Expression('expr', 'alias') @@ -155,9 +149,9 @@ class Expression extends Component * * @return Expression|null */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * Whether current tokens make an expression or a table reference. @@ -192,10 +186,10 @@ class Expression extends Component * * @var Token[] */ - $prev = array( + $prev = [ + null, null, - null - ); + ]; // When a field is parsed, no parentheses are expected. if (! empty($options['parseField'])) { @@ -269,7 +263,7 @@ class Expression extends Component continue; } $isExpr = true; - } elseif ($brackets === 0 && strlen($ret->expr) > 0 && ! $alias) { + } elseif ($brackets === 0 && strlen((string) $ret->expr) > 0 && ! $alias) { /* End of expression */ break; } @@ -413,7 +407,7 @@ class Expression extends Component } // White-spaces might be added at the end. - $ret->expr = trim($ret->expr); + $ret->expr = trim((string) $ret->expr); if ($ret->expr === '') { return null; @@ -430,16 +424,16 @@ class Expression extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); } - if ($component->expr !== '' && ! is_null($component->expr)) { + if ($component->expr !== '' && $component->expr !== null) { $ret = $component->expr; } else { - $fields = array(); + $fields = []; if (isset($component->database) && ($component->database !== '')) { $fields[] = $component->database; } diff --git a/src/Components/ExpressionArray.php b/src/Components/ExpressionArray.php index cdec66b..186693d 100644 --- a/src/Components/ExpressionArray.php +++ b/src/Components/ExpressionArray.php @@ -1,8 +1,8 @@ <?php - /** * Parses a list of expressions delimited by a comma. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a list of expressions delimited by a comma. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ExpressionArray extends Component { @@ -27,9 +23,9 @@ class ExpressionArray extends Component * * @return Expression[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; /** * The state of the parser. @@ -115,9 +111,9 @@ class ExpressionArray extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { - $ret = array(); + $ret = []; foreach ($component as $frag) { $ret[] = $frag::build($frag); } diff --git a/src/Components/FunctionCall.php b/src/Components/FunctionCall.php index 8334676..b41e6b2 100644 --- a/src/Components/FunctionCall.php +++ b/src/Components/FunctionCall.php @@ -1,8 +1,8 @@ <?php - /** * Parses a function call. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a function call. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class FunctionCall extends Component { @@ -35,8 +31,6 @@ class FunctionCall extends Component public $parameters; /** - * Constructor. - * * @param string $name the name of the function to be called * @param array|ArrayObj $parameters the parameters of this function */ @@ -57,9 +51,9 @@ class FunctionCall extends Component * * @return FunctionCall */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * The state of the parser. @@ -112,7 +106,7 @@ class FunctionCall extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { return $component->name . $component->parameters; } diff --git a/src/Components/GroupKeyword.php b/src/Components/GroupKeyword.php index c782288..888fb89 100644 --- a/src/Components/GroupKeyword.php +++ b/src/Components/GroupKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `GROUP BY` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,13 +13,11 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `GROUP BY` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class GroupKeyword extends Component { + public $type; + /** * The expression that is used for grouping. * @@ -28,8 +26,6 @@ class GroupKeyword extends Component public $expr; /** - * Constructor. - * * @param Expression $expr the expression that we are sorting by */ public function __construct($expr = null) @@ -44,11 +40,11 @@ class GroupKeyword extends Component * * @return GroupKeyword[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; - $expr = new self(); + $expr = new static(); /** * The state of the parser. @@ -96,7 +92,7 @@ class GroupKeyword extends Component if (! empty($expr->expr)) { $ret[] = $expr; } - $expr = new self(); + $expr = new static(); $state = 0; } else { break; @@ -120,12 +116,12 @@ class GroupKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); } - return trim($component->expr); + return trim((string) $component->expr); } } diff --git a/src/Components/IndexHint.php b/src/Components/IndexHint.php index 254152e..9b2f44e 100644 --- a/src/Components/IndexHint.php +++ b/src/Components/IndexHint.php @@ -1,8 +1,8 @@ <?php - /** * Parses an Index hint. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses an Index hint. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class IndexHint extends Component { @@ -46,17 +42,15 @@ class IndexHint extends Component * * @var array */ - public $indexes = array(); + public $indexes = []; /** - * Constructor. - * * @param string $type the type of hint (USE/FORCE/IGNORE) * @param string $indexOrKey What the hint is for (INDEX/KEY) * @param string $for the clause for which this hint is (JOIN/ORDER BY/GROUP BY) - * @param string $indexes List of indexes in this hint + * @param array $indexes List of indexes in this hint */ - public function __construct(string $type = null, string $indexOrKey = null, string $for = null, array $indexes = array()) + public function __construct(string $type = null, string $indexOrKey = null, string $for = null, array $indexes = []) { $this->type = $type; $this->indexOrKey = $indexOrKey; @@ -71,10 +65,10 @@ class IndexHint extends Component * * @return IndexHint|Component[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); - $expr = new self(); + $ret = []; + $expr = new static(); $expr->type = isset($options['type']) ? $options['type'] : null; /** * The state of the parser. @@ -86,6 +80,7 @@ class IndexHint extends Component * 2 -------------------- [ expr_list ] --------------------> 0 * 3 -------------- [ JOIN/GROUP BY/ORDER BY ] -------------> 4 * 4 -------------------- [ expr_list ] --------------------> 0 + * * @var int */ $state = 0; @@ -143,7 +138,7 @@ class IndexHint extends Component $expr->indexes = ExpressionArray::parse($parser, $list); $state = 0; $ret[] = $expr; - $expr = new self(); + $expr = new static(); } break; case 3: @@ -163,7 +158,7 @@ class IndexHint extends Component $expr->indexes = ExpressionArray::parse($parser, $list); $state = 0; $ret[] = $expr; - $expr = new self(); + $expr = new static(); break; } } @@ -173,12 +168,12 @@ class IndexHint extends Component } /** - * @param ArrayObj|ArrayObj[] $component the component to be built - * @param array $options parameters for building + * @param IndexHint|IndexHint[] $component the component to be built + * @param array $options parameters for building * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(' ', $component); diff --git a/src/Components/IntoKeyword.php b/src/Components/IntoKeyword.php index dea5d9d..c3f8a43 100644 --- a/src/Components/IntoKeyword.php +++ b/src/Components/IntoKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `INTO` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `INTO` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class IntoKeyword extends Component { @@ -25,37 +21,37 @@ class IntoKeyword extends Component * * @var array */ - public static $FIELDS_OPTIONS = array( - 'TERMINATED BY' => array( + public static $FIELDS_OPTIONS = [ + 'TERMINATED BY' => [ 1, 'expr', - ), + ], 'OPTIONALLY' => 2, - 'ENCLOSED BY' => array( + 'ENCLOSED BY' => [ 3, 'expr', - ), - 'ESCAPED BY' => array( + ], + 'ESCAPED BY' => [ 4, 'expr', - ) - ); + ], + ]; /** * LINES Options for `SELECT...INTO` statements. * * @var array */ - public static $LINES_OPTIONS = array( - 'STARTING BY' => array( + public static $LINES_OPTIONS = [ + 'STARTING BY' => [ 1, 'expr', - ), - 'TERMINATED BY' => array( + ], + 'TERMINATED BY' => [ 2, 'expr', - ) - ); + ], + ]; /** * Type of target (OUTFILE or SYMBOL). @@ -88,9 +84,9 @@ class IntoKeyword extends Component /** * Options for FIELDS/COLUMNS keyword. * - * @var OptionsArray - * * @see static::$FIELDS_OPTIONS + * + * @var OptionsArray */ public $fields_options; @@ -104,15 +100,13 @@ class IntoKeyword extends Component /** * Options for OPTIONS keyword. * - * @var OptionsArray - * * @see static::$LINES_OPTIONS + * + * @var OptionsArray */ public $lines_options; /** - * Constructor. - * * @param string $type type of destination (may be OUTFILE) * @param string|Expression $dest actual destination * @param array $columns column list of destination @@ -143,9 +137,9 @@ class IntoKeyword extends Component * * @return IntoKeyword */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * The state of the parser. @@ -203,10 +197,10 @@ class IntoKeyword extends Component $ret->dest = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); } else { $ret->values = ExpressionArray::parse($parser, $list); @@ -269,7 +263,7 @@ class IntoKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if ($component->dest instanceof Expression) { $columns = ! empty($component->columns) ? '(`' . implode('`, `', $component->columns) . '`)' : ''; @@ -287,7 +281,7 @@ class IntoKeyword extends Component $ret .= ' ' . $fields_options_str; } - $lines_options_str = OptionsArray::build($component->lines_options, array('expr' => true)); + $lines_options_str = OptionsArray::build($component->lines_options, ['expr' => true]); if (trim($lines_options_str) !== '') { $ret .= ' LINES ' . $lines_options_str; } diff --git a/src/Components/JoinKeyword.php b/src/Components/JoinKeyword.php index afc62ba..91bab01 100644 --- a/src/Components/JoinKeyword.php +++ b/src/Components/JoinKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `JOIN` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `JOIN` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class JoinKeyword extends Component { @@ -25,7 +21,7 @@ class JoinKeyword extends Component * * @var array */ - public static $JOINS = array( + public static $JOINS = [ 'CROSS JOIN' => 'CROSS', 'FULL JOIN' => 'FULL', 'FULL OUTER JOIN' => 'FULL', @@ -40,8 +36,8 @@ class JoinKeyword extends Component 'NATURAL RIGHT JOIN' => 'NATURAL RIGHT', 'NATURAL LEFT OUTER JOIN' => 'NATURAL LEFT OUTER', 'NATURAL RIGHT OUTER JOIN' => 'NATURAL RIGHT OUTER', - 'STRAIGHT_JOIN' => 'STRAIGHT' - ); + 'STRAIGHT_JOIN' => 'STRAIGHT', + ]; /** * Type of this join. @@ -74,14 +70,12 @@ class JoinKeyword extends Component public $using; /** - * Constructor. + * @see JoinKeyword::$JOINS * * @param string $type Join type * @param Expression $expr join expression * @param Condition[] $on join conditions * @param ArrayObj $using columns joined - * - * @see JoinKeyword::$JOINS */ public function __construct($type = null, $expr = null, $on = null, $using = null) { @@ -98,11 +92,11 @@ class JoinKeyword extends Component * * @return JoinKeyword[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; - $expr = new self(); + $expr = new static(); /** * The state of the parser. @@ -159,7 +153,7 @@ class JoinKeyword extends Component break; } } elseif ($state === 1) { - $expr->expr = Expression::parse($parser, $list, array('field' => 'table')); + $expr->expr = Expression::parse($parser, $list, ['field' => 'table']); $state = 2; } elseif ($state === 2) { if ($token->type === Token::TYPE_KEYWORD) { @@ -174,7 +168,7 @@ class JoinKeyword extends Component if (! empty(static::$JOINS[$token->keyword]) ) { $ret[] = $expr; - $expr = new self(); + $expr = new static(); $expr->type = static::$JOINS[$token->keyword]; $state = 1; } else { @@ -187,12 +181,12 @@ class JoinKeyword extends Component } elseif ($state === 3) { $expr->on = Condition::parse($parser, $list); $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; } elseif ($state === 4) { $expr->using = ArrayObj::parse($parser, $list); $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; } } @@ -212,9 +206,9 @@ class JoinKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { - $ret = array(); + $ret = []; foreach ($component as $c) { $ret[] = array_search($c->type, static::$JOINS) . ' ' . $c->expr . (! empty($c->on) diff --git a/src/Components/Key.php b/src/Components/Key.php index bf87e54..669a7c0 100644 --- a/src/Components/Key.php +++ b/src/Components/Key.php @@ -1,8 +1,8 @@ <?php - /** * Parses the definition of a key. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -16,10 +16,6 @@ use PhpMyAdmin\SqlParser\TokensList; * Parses the definition of a key. * * Used for parsing `CREATE TABLE` statement. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Key extends Component { @@ -28,24 +24,24 @@ class Key extends Component * * @var array */ - public static $KEY_OPTIONS = array( - 'KEY_BLOCK_SIZE' => array( + public static $KEY_OPTIONS = [ + 'KEY_BLOCK_SIZE' => [ 1, 'var', - ), - 'USING' => array( + ], + 'USING' => [ 2, 'var', - ), - 'WITH PARSER' => array( + ], + 'WITH PARSER' => [ 3, 'var', - ), - 'COMMENT' => array( + ], + 'COMMENT' => [ 4, 'var=', - ) - ); + ], + ]; /** * The name of this key. @@ -76,8 +72,6 @@ class Key extends Component public $options; /** - * Constructor. - * * @param string $name the name of the key * @param array $columns the columns covered by this key * @param string $type the type of this key @@ -85,7 +79,7 @@ class Key extends Component */ public function __construct( $name = null, - array $columns = array(), + array $columns = [], $type = null, $options = null ) { @@ -102,16 +96,16 @@ class Key extends Component * * @return Key */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * Last parsed column. * * @var array */ - $lastColumn = array(); + $lastColumn = []; /** * The state of the parser. @@ -161,10 +155,10 @@ class Key extends Component if ($token->value === '(') { $state = 3; } elseif (($token->value === ',') || ($token->value === ')')) { - $state = ($token->value === ',') ? 2 : 4; + $state = $token->value === ',' ? 2 : 4; if (! empty($lastColumn)) { $ret->columns[] = $lastColumn; - $lastColumn = array(); + $lastColumn = []; } } } else { @@ -194,14 +188,14 @@ class Key extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { $ret = $component->type . ' '; if (! empty($component->name)) { $ret .= Context::escape($component->name) . ' '; } - $columns = array(); + $columns = []; foreach ($component->columns as $column) { $tmp = Context::escape($column['name']); if (isset($column['length'])) { diff --git a/src/Components/Limit.php b/src/Components/Limit.php index a3903b5..16dad29 100644 --- a/src/Components/Limit.php +++ b/src/Components/Limit.php @@ -1,8 +1,8 @@ <?php - /** * `LIMIT` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `LIMIT` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Limit extends Component { @@ -35,8 +31,6 @@ class Limit extends Component public $rowCount; /** - * Constructor. - * * @param int $rowCount the row count * @param int $offset the offset */ @@ -53,9 +47,9 @@ class Limit extends Component * * @return Limit */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); $offset = false; @@ -126,7 +120,7 @@ class Limit extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { return $component->offset . ', ' . $component->rowCount; } diff --git a/src/Components/LockExpression.php b/src/Components/LockExpression.php index 1a2479d..6184f2e 100644 --- a/src/Components/LockExpression.php +++ b/src/Components/LockExpression.php @@ -1,8 +1,8 @@ <?php - /** * Parses a reference to a LOCK expression. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Parses a reference to a LOCK expression. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class LockExpression extends Component { @@ -39,11 +35,11 @@ class LockExpression extends Component * @param TokensList $list the list of tokens that are being parsed * @param array $options parameters for parsing * - * @return CaseExpression + * @return LockExpression */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * The state of the parser. @@ -77,7 +73,7 @@ class LockExpression extends Component } if ($state === 0) { - $ret->table = Expression::parse($parser, $list, array('parseField' => 'table')); + $ret->table = Expression::parse($parser, $list, ['parseField' => 'table']); $state = 1; } elseif ($state === 1) { // parse lock type @@ -103,7 +99,7 @@ class LockExpression extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/OptionsArray.php b/src/Components/OptionsArray.php index 69aabb3..da73dc6 100644 --- a/src/Components/OptionsArray.php +++ b/src/Components/OptionsArray.php @@ -1,8 +1,8 @@ <?php - /** * Parses a list of options. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Translator; /** * Parses a list of options. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OptionsArray extends Component { @@ -26,16 +22,14 @@ class OptionsArray extends Component * * @var array */ - public $options = array(); + public $options = []; /** - * Constructor. - * * @param array $options The array of options. Options that have a value * must be an array with at least two keys `name` and * `expr` or `value`. */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { $this->options = $options; } @@ -47,9 +41,9 @@ class OptionsArray extends Component * * @return OptionsArray */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * The ID that will be assigned to duplicate options. @@ -167,7 +161,7 @@ class OptionsArray extends Component // This is only the beginning. The value is parsed in state // 1 and 2. State 1 is used to skip the first equals sign // and state 2 to parse the actual value. - $ret->options[$lastOptionId] = array( + $ret->options[$lastOptionId] = [ // @var string The name of the option. 'name' => $token->value, // @var bool Whether it contains an equal sign. @@ -176,8 +170,8 @@ class OptionsArray extends Component // @var string Raw value. 'expr' => '', // @var string Processed value. - 'value' => '' - ); + 'value' => '', + ]; $state = 1; } elseif ($lastOption[1] === 'expr' || $lastOption[1] === 'expr=') { // This is a keyword that is followed by an expression. @@ -185,15 +179,15 @@ class OptionsArray extends Component // Skipping this option in order to parse the expression. ++$list->idx; - $ret->options[$lastOptionId] = array( + $ret->options[$lastOptionId] = [ // @var string The name of the option. 'name' => $token->value, // @var bool Whether it contains an equal sign. // This is used by the builder to rebuild it. 'equals' => $lastOption[1] === 'expr=', // @var Expression The parsed expression. - 'expr' => '' - ); + 'expr' => '', + ]; $state = 1; } } elseif ($state === 1) { @@ -211,7 +205,7 @@ class OptionsArray extends Component $ret->options[$lastOptionId]['expr'] = Expression::parse( $parser, $list, - empty($lastOption[2]) ? array() : $lastOption[2] + empty($lastOption[2]) ? [] : $lastOption[2] ); $ret->options[$lastOptionId]['value'] = $ret->options[$lastOptionId]['expr']->expr; @@ -276,19 +270,19 @@ class OptionsArray extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (empty($component->options)) { return ''; } - $options = array(); + $options = []; foreach ($component->options as $option) { if (! is_array($option)) { $options[] = $option; } else { $options[] = $option['name'] - . ((! empty($option['equals']) && $option['equals']) ? '=' : ' ') + . (! empty($option['equals']) && $option['equals'] ? '=' : ' ') . (! empty($option['expr']) ? $option['expr'] : $option['value']); } } diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php index 1e77f57..966758e 100644 --- a/src/Components/OrderKeyword.php +++ b/src/Components/OrderKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `ORDER BY` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `ORDER BY` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OrderKeyword extends Component { @@ -35,8 +31,6 @@ class OrderKeyword extends Component public $type; /** - * Constructor. - * * @param Expression $expr the expression that we are sorting by * @param string $type the sorting type */ @@ -53,11 +47,11 @@ class OrderKeyword extends Component * * @return OrderKeyword[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; - $expr = new self(); + $expr = new static(); /** * The state of the parser. @@ -105,7 +99,7 @@ class OrderKeyword extends Component if (! empty($expr->expr)) { $ret[] = $expr; } - $expr = new self(); + $expr = new static(); $state = 0; } else { break; @@ -129,7 +123,7 @@ class OrderKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/ParameterDefinition.php b/src/Components/ParameterDefinition.php index 831ee4b..d7aa293 100644 --- a/src/Components/ParameterDefinition.php +++ b/src/Components/ParameterDefinition.php @@ -1,8 +1,8 @@ <?php - /** * The definition of a parameter of a function or procedure. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * The definition of a parameter of a function or procedure. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ParameterDefinition extends Component { @@ -43,8 +39,6 @@ class ParameterDefinition extends Component public $type; /** - * Constructor. - * * @param string $name parameter's name * @param string $inOut parameter's directional type (IN / OUT or None) * @param DataType $type parameter's type @@ -63,11 +57,11 @@ class ParameterDefinition extends Component * * @return ParameterDefinition[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; - $expr = new self(); + $expr = new static(); /** * The state of the parser. @@ -127,7 +121,7 @@ class ParameterDefinition extends Component $state = 3; } elseif ($state === 3) { $ret[] = $expr; - $expr = new self(); + $expr = new static(); if ($token->value === ',') { $state = 1; } elseif ($token->value === ')') { @@ -153,7 +147,7 @@ class ParameterDefinition extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return '(' . implode(', ', $component) . ')'; diff --git a/src/Components/PartitionDefinition.php b/src/Components/PartitionDefinition.php index 53da148..e67e92f 100644 --- a/src/Components/PartitionDefinition.php +++ b/src/Components/PartitionDefinition.php @@ -1,10 +1,10 @@ <?php - /** * Parses the create definition of a partition. * * Used for parsing `CREATE TABLE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -17,10 +17,6 @@ use PhpMyAdmin\SqlParser\TokensList; * Parses the create definition of a partition. * * Used for parsing `CREATE TABLE` statement. - * - * @category Components - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class PartitionDefinition extends Component { @@ -29,44 +25,44 @@ class PartitionDefinition extends Component * * @var array */ - public static $OPTIONS = array( - 'STORAGE ENGINE' => array( + public static $OPTIONS = [ + 'STORAGE ENGINE' => [ 1, 'var', - ), - 'ENGINE' => array( + ], + 'ENGINE' => [ 1, 'var', - ), - 'COMMENT' => array( + ], + 'COMMENT' => [ 2, 'var', - ), - 'DATA DIRECTORY' => array( + ], + 'DATA DIRECTORY' => [ 3, 'var', - ), - 'INDEX DIRECTORY' => array( + ], + 'INDEX DIRECTORY' => [ 4, 'var', - ), - 'MAX_ROWS' => array( + ], + 'MAX_ROWS' => [ 5, 'var', - ), - 'MIN_ROWS' => array( + ], + 'MIN_ROWS' => [ 6, 'var', - ), - 'TABLESPACE' => array( + ], + 'TABLESPACE' => [ 7, 'var', - ), - 'NODEGROUP' => array( + ], + 'NODEGROUP' => [ 8, 'var', - ) - ); + ], + ]; /** * Whether this entry is a subpartition or a partition. @@ -117,9 +113,9 @@ class PartitionDefinition extends Component * * @return PartitionDefinition */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * The state of the parser. @@ -196,10 +192,10 @@ class PartitionDefinition extends Component $ret->expr = Expression::parse( $parser, $list, - array( + [ 'parenthesesDelimited' => true, - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); } $state = 5; @@ -211,9 +207,9 @@ class PartitionDefinition extends Component $ret->subpartitions = ArrayObj::parse( $parser, $list, - array( - 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition' - ) + [ + 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition', + ] ); ++$list->idx; } @@ -232,7 +228,7 @@ class PartitionDefinition extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return "(\n" . implode(",\n", $component) . "\n)"; @@ -247,7 +243,7 @@ class PartitionDefinition extends Component return trim( 'PARTITION ' . $component->name . (empty($component->type) ? '' : ' VALUES ' . $component->type . ' ' . $component->expr . ' ') - . ((! empty($component->options) && ! empty($component->type)) ? '' : ' ') . $component->options . $subpartitions + . (! empty($component->options) && ! empty($component->type) ? '' : ' ') . $component->options . $subpartitions ); } } diff --git a/src/Components/Reference.php b/src/Components/Reference.php index 38fc060..759f3ad 100644 --- a/src/Components/Reference.php +++ b/src/Components/Reference.php @@ -1,8 +1,8 @@ <?php - /** * `REFERENCES` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `REFERENCES` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Reference extends Component { @@ -26,20 +22,20 @@ class Reference extends Component * * @var array */ - public static $REFERENCES_OPTIONS = array( - 'MATCH' => array( + public static $REFERENCES_OPTIONS = [ + 'MATCH' => [ 1, 'var', - ), - 'ON DELETE' => array( + ], + 'ON DELETE' => [ 2, 'var', - ), - 'ON UPDATE' => array( + ], + 'ON UPDATE' => [ 3, 'var', - ) - ); + ], + ]; /** * The referenced table. @@ -63,13 +59,11 @@ class Reference extends Component public $options; /** - * Constructor. - * * @param Expression $table the name of the table referenced * @param array $columns the columns referenced * @param OptionsArray $options the options */ - public function __construct($table = null, array $columns = array(), $options = null) + public function __construct($table = null, array $columns = [], $options = null) { $this->table = $table; $this->columns = $columns; @@ -83,9 +77,9 @@ class Reference extends Component * * @return Reference */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = new self(); + $ret = new static(); /** * The state of the parser. @@ -124,10 +118,10 @@ class Reference extends Component $ret->table = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); $state = 1; } elseif ($state === 1) { @@ -151,7 +145,7 @@ class Reference extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { return trim( $component->table diff --git a/src/Components/RenameOperation.php b/src/Components/RenameOperation.php index bf6167b..a2a8d1f 100644 --- a/src/Components/RenameOperation.php +++ b/src/Components/RenameOperation.php @@ -1,8 +1,8 @@ <?php - /** * `RENAME TABLE` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `RENAME TABLE` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RenameOperation extends Component { @@ -35,8 +31,6 @@ class RenameOperation extends Component public $new; /** - * Constructor. - * * @param Expression $old old expression * @param Expression $new new expression containing new name */ @@ -53,11 +47,11 @@ class RenameOperation extends Component * * @return RenameOperation[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; - $expr = new self(); + $expr = new static(); /** * The state of the parser. @@ -99,10 +93,10 @@ class RenameOperation extends Component $expr->old = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, - 'parseField' => 'table' - ) + 'parseField' => 'table', + ] ); if (empty($expr->old)) { $parser->error( @@ -125,10 +119,10 @@ class RenameOperation extends Component $expr->new = Expression::parse( $parser, $list, - array( + [ 'breakOnAlias' => true, - 'parseField' => 'table' - ) + 'parseField' => 'table', + ] ); if (empty($expr->new)) { $parser->error( @@ -140,7 +134,7 @@ class RenameOperation extends Component } elseif ($state === 3) { if (($token->type === Token::TYPE_OPERATOR) && ($token->value === ',')) { $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; } else { break; @@ -171,7 +165,7 @@ class RenameOperation extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/SetOperation.php b/src/Components/SetOperation.php index d27819c..1e44650 100644 --- a/src/Components/SetOperation.php +++ b/src/Components/SetOperation.php @@ -1,8 +1,8 @@ <?php - /** * `SET` keyword parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `SET` keyword parser. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class SetOperation extends Component { @@ -35,8 +31,6 @@ class SetOperation extends Component public $value; /** - * Constructor. - * * @param string $column Field's name.. * @param string $value new value */ @@ -53,11 +47,11 @@ class SetOperation extends Component * * @return SetOperation[] */ - public static function parse(Parser $parser, TokensList $list, array $options = array()) + public static function parse(Parser $parser, TokensList $list, array $options = []) { - $ret = array(); + $ret = []; - $expr = new self(); + $expr = new static(); /** * The state of the parser. @@ -118,18 +112,18 @@ class SetOperation extends Component $tmp = Expression::parse( $parser, $list, - array( - 'breakOnAlias' => true - ) + [ + 'breakOnAlias' => true, + ] ); - if (is_null($tmp)) { + if ($tmp === null) { $parser->error('Missing expression.', $token); break; } $expr->column = trim($expr->column); $expr->value = $tmp->expr; $ret[] = $expr; - $expr = new self(); + $expr = new static(); $state = 0; $commaLastSeenAt = null; } @@ -150,7 +144,7 @@ class SetOperation extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { if (is_array($component)) { return implode(', ', $component); diff --git a/src/Components/UnionKeyword.php b/src/Components/UnionKeyword.php index 6867615..55c9e29 100644 --- a/src/Components/UnionKeyword.php +++ b/src/Components/UnionKeyword.php @@ -1,8 +1,8 @@ <?php - /** * `UNION` keyword builder. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Components; @@ -10,10 +10,6 @@ use PhpMyAdmin\SqlParser\Component; /** * `UNION` keyword builder. - * - * @category Keywords - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class UnionKeyword extends Component { @@ -23,9 +19,9 @@ class UnionKeyword extends Component * * @return string */ - public static function build($component, array $options = array()) + public static function build($component, array $options = []) { - $tmp = array(); + $tmp = []; foreach ($component as $componentPart) { $tmp[] = $componentPart[0] . ' ' . $componentPart[1]; } diff --git a/src/Context.php b/src/Context.php index 93c1c76..138c5c5 100644 --- a/src/Context.php +++ b/src/Context.php @@ -1,11 +1,11 @@ <?php - /** * Defines a context class that is later extended to define other contexts. * * A context is a collection of keywords, operators and functions used for * parsing. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\Exceptions\LoaderException; /** * Holds the configuration of the context that is currently used. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ abstract class Context { @@ -86,14 +82,14 @@ abstract class Context * * @var array */ - public static $KEYWORDS = array(); + public static $KEYWORDS = []; /** * List of operators and their flags. * * @var array */ - public static $OPERATORS = array( + public static $OPERATORS = [ // Some operators (*, =) may have ambiguous flags, because they depend on // the context they are being used in. // For example: 1. SELECT * FROM table; # SQL specific (wildcard) @@ -137,8 +133,8 @@ abstract class Context ')' => 16, '.' => 16, ',' => 16, - ';' => 16 - ); + ';' => 16, + ]; /** * The mode of the MySQL server that will be used in lexing, parsing and @@ -339,7 +335,7 @@ abstract class Context if ($str[0] === '#') { return Token::FLAG_COMMENT_BASH; } elseif (($len > 1) && ($str[0] === '/') && ($str[1] === '*')) { - return (($len > 2) && ($str[2] === '!')) ? + return ($len > 2) && ($str[2] === '!') ? Token::FLAG_COMMENT_MYSQL_CMD : Token::FLAG_COMMENT_C; } elseif (($len > 1) && ($str[0] === '*') && ($str[1] === '/')) { return Token::FLAG_COMMENT_C; @@ -385,7 +381,7 @@ abstract class Context */ public static function isNumber($str) { - return (($str >= '0') && ($str <= '9')) || ($str === '.') + return ($str >= '0') && ($str <= '9') || ($str === '.') || ($str === '-') || ($str === '+') || ($str === 'e') || ($str === 'E'); } @@ -468,7 +464,7 @@ abstract class Context * @param string $context name of the context or full class name that * defines the context * - * @throws LoaderException if the specified context doesn't exist + * @throws LoaderException if the specified context doesn't exist. */ public static function load($context = '') { diff --git a/src/Contexts/ContextMariaDb100000.php b/src/Contexts/ContextMariaDb100000.php index e4c368d..b6646bb 100644 --- a/src/Contexts/ContextMariaDb100000.php +++ b/src/Contexts/ContextMariaDb100000.php @@ -1,5 +1,4 @@ <?php - /** * Context for MariaDB 10.0. * @@ -7,6 +6,7 @@ * * @see https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MariaDB 10.0. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMariaDb100000 extends Context { @@ -33,7 +29,7 @@ class ContextMariaDb100000 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, @@ -311,6 +307,6 @@ class ContextMariaDb100000 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMariaDb100100.php b/src/Contexts/ContextMariaDb100100.php index 26ce58b..9eca83a 100644 --- a/src/Contexts/ContextMariaDb100100.php +++ b/src/Contexts/ContextMariaDb100100.php @@ -1,5 +1,4 @@ <?php - /** * Context for MariaDB 10.1. * @@ -7,6 +6,7 @@ * * @see https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MariaDB 10.1. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMariaDb100100 extends Context { @@ -33,7 +29,7 @@ class ContextMariaDb100100 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, @@ -360,6 +356,6 @@ class ContextMariaDb100100 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMariaDb100200.php b/src/Contexts/ContextMariaDb100200.php index 911afe8..8f088aa 100644 --- a/src/Contexts/ContextMariaDb100200.php +++ b/src/Contexts/ContextMariaDb100200.php @@ -1,5 +1,4 @@ <?php - /** * Context for MariaDB 10.2. * @@ -7,6 +6,7 @@ * * @see https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MariaDB 10.2. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMariaDb100200 extends Context { @@ -33,7 +29,7 @@ class ContextMariaDb100200 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, @@ -360,6 +356,6 @@ class ContextMariaDb100200 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMariaDb100300.php b/src/Contexts/ContextMariaDb100300.php index e30ab04..c631731 100644 --- a/src/Contexts/ContextMariaDb100300.php +++ b/src/Contexts/ContextMariaDb100300.php @@ -1,5 +1,4 @@ <?php - /** * Context for MariaDB 10.3. * @@ -7,6 +6,7 @@ * * @see https://mariadb.com/kb/en/the-mariadb-library/reserved-words/ */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MariaDB 10.3. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMariaDb100300 extends Context { @@ -33,7 +29,7 @@ class ContextMariaDb100300 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, @@ -360,6 +356,6 @@ class ContextMariaDb100300 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50000.php b/src/Contexts/ContextMySql50000.php index 63f12fe..7621623 100644 --- a/src/Contexts/ContextMySql50000.php +++ b/src/Contexts/ContextMySql50000.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.0. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.0/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MySQL 5.0. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50000 extends Context { @@ -33,7 +29,7 @@ class ContextMySql50000 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'BDB' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, @@ -281,6 +277,6 @@ class ContextMySql50000 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50100.php b/src/Contexts/ContextMySql50100.php index 4b97896..dbf8f86 100644 --- a/src/Contexts/ContextMySql50100.php +++ b/src/Contexts/ContextMySql50100.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.1. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.1/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MySQL 5.1. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50100 extends Context { @@ -33,7 +29,7 @@ class ContextMySql50100 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'BDB' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, @@ -306,6 +302,6 @@ class ContextMySql50100 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50500.php b/src/Contexts/ContextMySql50500.php index 4d1de76..b5b0f26 100644 --- a/src/Contexts/ContextMySql50500.php +++ b/src/Contexts/ContextMySql50500.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.5. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.5/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MySQL 5.5. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50500 extends Context { @@ -33,7 +29,7 @@ class ContextMySql50500 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, @@ -311,6 +307,6 @@ class ContextMySql50500 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50600.php b/src/Contexts/ContextMySql50600.php index e447ec7..f60ae05 100644 --- a/src/Contexts/ContextMySql50600.php +++ b/src/Contexts/ContextMySql50600.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.6. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.6/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MySQL 5.6. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50600 extends Context { @@ -33,7 +29,7 @@ class ContextMySql50600 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, @@ -340,6 +336,6 @@ class ContextMySql50600 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql50700.php b/src/Contexts/ContextMySql50700.php index bf77167..412c25b 100644 --- a/src/Contexts/ContextMySql50700.php +++ b/src/Contexts/ContextMySql50700.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 5.7. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/5.7/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MySQL 5.7. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql50700 extends Context { @@ -33,7 +29,7 @@ class ContextMySql50700 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, @@ -360,6 +356,6 @@ class ContextMySql50700 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Contexts/ContextMySql80000.php b/src/Contexts/ContextMySql80000.php index 05fc4c9..bfc265f 100644 --- a/src/Contexts/ContextMySql80000.php +++ b/src/Contexts/ContextMySql80000.php @@ -1,5 +1,4 @@ <?php - /** * Context for MySQL 8.0. * @@ -7,6 +6,7 @@ * * @see https://dev.mysql.com/doc/refman/8.0/en/keywords.html */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Contexts; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Token; /** * Context for MySQL 8.0. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextMySql80000 extends Context { @@ -33,7 +29,7 @@ class ContextMySql80000 extends Context * * @var array */ - public static $KEYWORDS = array( + public static $KEYWORDS = [ 'AT' => 1, 'DO' => 1, 'IO' => 1, 'NO' => 1, 'XA' => 1, 'ANY' => 1, 'CPU' => 1, 'END' => 1, 'IPC' => 1, 'NDB' => 1, 'NEW' => 1, 'ONE' => 1, 'ROW' => 1, 'XID' => 1, @@ -360,6 +356,6 @@ class ContextMySql80000 extends Context 'CHAR' => 43, 'BINARY' => 43, - 'INTERVAL' => 43 - ); + 'INTERVAL' => 43, + ]; } diff --git a/src/Core.php b/src/Core.php index 052ac5e..1d3eeea 100644 --- a/src/Core.php +++ b/src/Core.php @@ -1,19 +1,21 @@ <?php - /** * Defines the core helper infrastructure of the library. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; +use Exception; + class Core { /** * Whether errors should throw exceptions or just be stored. * - * @var bool - * * @see static::$errors + * + * @var bool */ public $strict = false; @@ -24,18 +26,18 @@ class Core * error might be false positive or a partial result (even a bad one) * might be needed. * - * @var \Exception[] - * * @see Core::error() + * + * @var Exception[] */ - public $errors = array(); + public $errors = []; /** * Creates a new error log. * - * @param \Exception $error the error exception + * @param Exception $error the error exception * - * @throws \Exception throws the exception, if strict mode is enabled + * @throws Exception throws the exception, if strict mode is enabled. */ public function error($error) { diff --git a/src/Exceptions/LexerException.php b/src/Exceptions/LexerException.php index 61e88c9..9731575 100644 --- a/src/Exceptions/LexerException.php +++ b/src/Exceptions/LexerException.php @@ -1,19 +1,17 @@ <?php - /** * Exception thrown by the lexer. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Exceptions; +use Exception; + /** * Exception thrown by the lexer. - * - * @category Exceptions - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ -class LexerException extends \Exception +class LexerException extends Exception { /** * The character that produced this error. @@ -30,8 +28,6 @@ class LexerException extends \Exception public $pos; /** - * Constructor. - * * @param string $msg the message of this exception * @param string $ch the character that produced this exception * @param int $pos the position of the character diff --git a/src/Exceptions/LoaderException.php b/src/Exceptions/LoaderException.php index bfbd4c3..54b9234 100644 --- a/src/Exceptions/LoaderException.php +++ b/src/Exceptions/LoaderException.php @@ -1,19 +1,17 @@ <?php - /** * Exception thrown by the lexer. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Exceptions; +use Exception; + /** * Exception thrown by the lexer. - * - * @category Exceptions - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ -class LoaderException extends \Exception +class LoaderException extends Exception { /** * The failed load name. @@ -23,8 +21,6 @@ class LoaderException extends \Exception public $name; /** - * Constructor. - * * @param string $msg the message of this exception * @param string $name the character that produced this exception * @param int $code the code of this error diff --git a/src/Exceptions/ParserException.php b/src/Exceptions/ParserException.php index eb13653..ae63f07 100644 --- a/src/Exceptions/ParserException.php +++ b/src/Exceptions/ParserException.php @@ -1,21 +1,18 @@ <?php - /** * Exception thrown by the parser. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Exceptions; +use Exception; use PhpMyAdmin\SqlParser\Token; /** * Exception thrown by the parser. - * - * @category Exceptions - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ -class ParserException extends \Exception +class ParserException extends Exception { /** * The token that produced this error. @@ -25,8 +22,6 @@ class ParserException extends \Exception public $token; /** - * Constructor. - * * @param string $msg the message of this exception * @param Token $token the token that produced this exception * @param int $code the code of this error diff --git a/src/Lexer.php b/src/Lexer.php index 895cb2b..2479410 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -1,5 +1,4 @@ <?php - /** * Defines the lexer of the library. * @@ -7,6 +6,7 @@ * * Depends on context to extract lexemes. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -33,10 +33,6 @@ if (! defined('USE_UTF_STRINGS')) { * * The output of the lexer is affected by the context of the SQL statement. * - * @category Lexer - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ - * * @see Context */ class Lexer extends Core @@ -46,7 +42,7 @@ class Lexer extends Core * * @var array */ - public static $PARSER_METHODS = array( + public static $PARSER_METHODS = [ // It is best to put the parsers in order of their complexity // (ascending) and their occurrence rate (descending). // @@ -80,8 +76,8 @@ class Lexer extends Core 'parseSymbol', 'parseKeyword', 'parseLabel', - 'parseUnknown' - ); + 'parseUnknown', + ]; /** * The string to be parsed. @@ -158,8 +154,6 @@ class Lexer extends Core } /** - * Constructor. - * * @param string|UtfString $str the query to be lexed * @param bool $strict whether strict mode should be * enabled or not @@ -353,7 +347,7 @@ class Lexer extends Core * @param int $pos the position of the character * @param int $code the code of the error * - * @throws LexerException throws the exception, if strict mode is enabled + * @throws LexerException throws the exception, if strict mode is enabled. */ public function error($msg, $str = '', $pos = 0, $code = 0) { diff --git a/src/Parser.php b/src/Parser.php index ab3e1b7..902fa49 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -1,10 +1,10 @@ <?php - /** * Defines the parser of the library. * * This is one of the most important components, along with the lexer. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\Statements\TransactionStatement; /** * Takes multiple tokens (contained in a Lexer instance) as input and builds a * parse tree. - * - * @category Parser - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Parser extends Core { @@ -27,7 +23,7 @@ class Parser extends Core * * @var array */ - public static $STATEMENT_PARSERS = array( + public static $STATEMENT_PARSERS = [ // MySQL Utility Statements 'DESCRIBE' => 'PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement', 'DESC' => 'PhpMyAdmin\\SqlParser\\Statements\\ExplainStatement', @@ -92,247 +88,247 @@ class Parser extends Core // Lock statements // https://dev.mysql.com/doc/refman/5.7/en/lock-tables.html 'LOCK' => 'PhpMyAdmin\\SqlParser\\Statements\\LockStatement', - 'UNLOCK' => 'PhpMyAdmin\\SqlParser\\Statements\\LockStatement' - ); + 'UNLOCK' => 'PhpMyAdmin\\SqlParser\\Statements\\LockStatement', + ]; /** * Array of classes that are used in parsing SQL components. * * @var array */ - public static $KEYWORD_PARSERS = array( + public static $KEYWORD_PARSERS = [ // This is not a proper keyword and was added here to help the // formatter. - 'PARTITION BY' => array(), - 'SUBPARTITION BY' => array(), + 'PARTITION BY' => [], + 'SUBPARTITION BY' => [], // This is not a proper keyword and was added here to help the // builder. - '_OPTIONS' => array( + '_OPTIONS' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\OptionsArray', 'field' => 'options', - ), - '_END_OPTIONS' => array( + ], + '_END_OPTIONS' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\OptionsArray', 'field' => 'end_options', - ), + ], - 'INTERSECT' => array( + 'INTERSECT' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword', 'field' => 'union', - ), - 'EXCEPT' => array( + ], + 'EXCEPT' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword', 'field' => 'union', - ), - 'UNION' => array( + ], + 'UNION' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword', 'field' => 'union', - ), - 'UNION ALL' => array( + ], + 'UNION ALL' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword', 'field' => 'union', - ), - 'UNION DISTINCT' => array( + ], + 'UNION DISTINCT' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\UnionKeyword', 'field' => 'union', - ), + ], // Actual clause parsers. - 'ALTER' => array( + 'ALTER' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\Expression', 'field' => 'table', - 'options' => array('parseField' => 'table'), - ), - 'ANALYZE' => array( + 'options' => ['parseField' => 'table'], + ], + 'ANALYZE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'tables', - 'options' => array('parseField' => 'table'), - ), - 'BACKUP' => array( + 'options' => ['parseField' => 'table'], + ], + 'BACKUP' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'tables', - 'options' => array('parseField' => 'table'), - ), - 'CALL' => array( + 'options' => ['parseField' => 'table'], + ], + 'CALL' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\FunctionCall', 'field' => 'call', - ), - 'CHECK' => array( + ], + 'CHECK' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'tables', - 'options' => array('parseField' => 'table'), - ), - 'CHECKSUM' => array( + 'options' => ['parseField' => 'table'], + ], + 'CHECKSUM' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'tables', - 'options' => array('parseField' => 'table'), - ), - 'CROSS JOIN' => array( + 'options' => ['parseField' => 'table'], + ], + 'CROSS JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'DROP' => array( + ], + 'DROP' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'fields', - 'options' => array('parseField' => 'table'), - ), - 'FORCE' => array( + 'options' => ['parseField' => 'table'], + ], + 'FORCE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\IndexHint', 'field' => 'index_hints', - ), - 'FROM' => array( + ], + 'FROM' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'from', - 'options' => array('field' => 'table'), - ), - 'GROUP BY' => array( + 'options' => ['field' => 'table'], + ], + 'GROUP BY' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\GroupKeyword', 'field' => 'group', - ), - 'HAVING' => array( + ], + 'HAVING' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\Condition', 'field' => 'having', - ), - 'IGNORE' => array( + ], + 'IGNORE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\IndexHint', 'field' => 'index_hints', - ), - 'INTO' => array( + ], + 'INTO' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\IntoKeyword', 'field' => 'into', - ), - 'JOIN' => array( + ], + 'JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'LEFT JOIN' => array( + ], + 'LEFT JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'LEFT OUTER JOIN' => array( + ], + 'LEFT OUTER JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'ON' => array( + ], + 'ON' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\Expression', 'field' => 'table', - 'options' => array('parseField' => 'table'), - ), - 'RIGHT JOIN' => array( + 'options' => ['parseField' => 'table'], + ], + 'RIGHT JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'RIGHT OUTER JOIN' => array( + ], + 'RIGHT OUTER JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'INNER JOIN' => array( + ], + 'INNER JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'FULL JOIN' => array( + ], + 'FULL JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'FULL OUTER JOIN' => array( + ], + 'FULL OUTER JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'NATURAL JOIN' => array( + ], + 'NATURAL JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'NATURAL LEFT JOIN' => array( + ], + 'NATURAL LEFT JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'NATURAL RIGHT JOIN' => array( + ], + 'NATURAL RIGHT JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'NATURAL LEFT OUTER JOIN' => array( + ], + 'NATURAL LEFT OUTER JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'NATURAL RIGHT OUTER JOIN' => array( + ], + 'NATURAL RIGHT OUTER JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'STRAIGHT_JOIN' => array( + ], + 'STRAIGHT_JOIN' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\JoinKeyword', 'field' => 'join', - ), - 'LIMIT' => array( + ], + 'LIMIT' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\Limit', 'field' => 'limit', - ), - 'OPTIMIZE' => array( + ], + 'OPTIMIZE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'tables', - 'options' => array('parseField' => 'table'), - ), - 'ORDER BY' => array( + 'options' => ['parseField' => 'table'], + ], + 'ORDER BY' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\OrderKeyword', 'field' => 'order', - ), - 'PARTITION' => array( + ], + 'PARTITION' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ArrayObj', 'field' => 'partition', - ), - 'PROCEDURE' => array( + ], + 'PROCEDURE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\FunctionCall', 'field' => 'procedure', - ), - 'RENAME' => array( + ], + 'RENAME' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\RenameOperation', 'field' => 'renames', - ), - 'REPAIR' => array( + ], + 'REPAIR' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'tables', - 'options' => array('parseField' => 'table'), - ), - 'RESTORE' => array( + 'options' => ['parseField' => 'table'], + ], + 'RESTORE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'tables', - 'options' => array('parseField' => 'table'), - ), - 'SET' => array( + 'options' => ['parseField' => 'table'], + ], + 'SET' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\SetOperation', 'field' => 'set', - ), - 'SELECT' => array( + ], + 'SELECT' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'expr', - ), - 'TRUNCATE' => array( + ], + 'TRUNCATE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\Expression', 'field' => 'table', - 'options' => array('parseField' => 'table'), - ), - 'UPDATE' => array( + 'options' => ['parseField' => 'table'], + ], + 'UPDATE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\ExpressionArray', 'field' => 'tables', - 'options' => array('parseField' => 'table'), - ), - 'USE' => array( + 'options' => ['parseField' => 'table'], + ], + 'USE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\IndexHint', 'field' => 'index_hints', - ), - 'VALUE' => array( + ], + 'VALUE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\Array2d', 'field' => 'values', - ), - 'VALUES' => array( + ], + 'VALUES' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\Array2d', 'field' => 'values', - ), - 'WHERE' => array( + ], + 'WHERE' => [ 'class' => 'PhpMyAdmin\\SqlParser\\Components\\Condition', 'field' => 'where', - ) - ); + ], + ]; /** * The list of tokens that are parsed. @@ -346,7 +342,7 @@ class Parser extends Core * * @var Statement[] */ - public $statements = array(); + public $statements = []; /** * The number of opened brackets. @@ -356,8 +352,6 @@ class Parser extends Core public $brackets = 0; /** - * Constructor. - * * @param string|UtfString|TokensList $list the list of tokens to be parsed * @param bool $strict whether strict mode should be enabled or not */ @@ -526,16 +520,16 @@ class Parser extends Core * * @var SelectStatement $lastStatement */ - $lastStatement->union[] = array( + $lastStatement->union[] = [ $unionType, - $statement - ); + $statement, + ]; // if there are no no delimiting brackets, the `ORDER` and // `LIMIT` keywords actually belong to the first statement. $lastStatement->order = $statement->order; $lastStatement->limit = $statement->limit; - $statement->order = array(); + $statement->order = []; $statement->limit = null; // The statement actually ends where the last statement in @@ -597,7 +591,7 @@ class Parser extends Core * @param Token $token the token that produced the error * @param int $code the code of the error * - * @throws ParserException throws the exception, if strict mode is enabled + * @throws ParserException throws the exception, if strict mode is enabled. */ public function error($msg, Token $token = null, $code = 0) { diff --git a/src/Statement.php b/src/Statement.php index f9e0902..6617da7 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -1,11 +1,11 @@ <?php - /** * The result of the parser is an array of statements are extensions of the * class defined here. * * A statement represents the result of parsing the lexemes. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Components\OptionsArray; /** * Abstract statement definition. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ abstract class Statement { @@ -40,7 +36,7 @@ abstract class Statement * * @var array */ - public static $OPTIONS = array(); + public static $OPTIONS = []; /** * The clauses of this statement, in order. @@ -54,16 +50,16 @@ abstract class Statement * * @var array */ - public static $CLAUSES = array(); + public static $CLAUSES = []; - public static $END_OPTIONS = array(); + public static $END_OPTIONS = []; /** * The options of this query. * - * @var OptionsArray - * * @see static::$OPTIONS + * + * @var OptionsArray */ public $options; @@ -82,8 +78,6 @@ abstract class Statement public $last; /** - * Constructor. - * * @param Parser $parser the instance that requests parsing * @param TokensList $list the list of tokens to be parsed */ @@ -120,7 +114,7 @@ abstract class Statement * * @var array */ - $built = array(); + $built = []; /** * Statement's clauses. @@ -202,7 +196,7 @@ abstract class Statement * * @var array */ - $parsedClauses = array(); + $parsedClauses = []; // This may be corrected by the parser. $this->first = $list->idx; @@ -303,7 +297,7 @@ abstract class Statement * * @var array */ - $options = array(); + $options = []; // Looking for duplicated clauses. if (! empty(Parser::$KEYWORD_PARSERS[$token->value]) @@ -323,7 +317,7 @@ abstract class Statement // Fix Issue #221: As `truncate` is not a keyword // but it might be the beginning of a statement of truncate, // so let the value use the keyword field for truncate type. - $token_value = in_array($token->keyword, array('TRUNCATE')) ? $token->keyword : $token->value; + $token_value = in_array($token->keyword, ['TRUNCATE']) ? $token->keyword : $token->value; if (! empty(Parser::$KEYWORD_PARSERS[$token_value]) && $list->idx < $list->count) { $class = Parser::$KEYWORD_PARSERS[$token_value]['class']; $field = Parser::$KEYWORD_PARSERS[$token_value]['field']; @@ -552,7 +546,7 @@ abstract class Statement $minIdx = $clauseStartIdx; } - $lastIdx = ($clauseStartIdx !== -1) ? $clauseStartIdx : $lastIdx; + $lastIdx = $clauseStartIdx !== -1 ? $clauseStartIdx : $lastIdx; } return true; diff --git a/src/Statements/AlterStatement.php b/src/Statements/AlterStatement.php index ce0c824..a03b2fc 100644 --- a/src/Statements/AlterStatement.php +++ b/src/Statements/AlterStatement.php @@ -1,8 +1,8 @@ <?php - /** * `ALTER` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -16,10 +16,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `ALTER` statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class AlterStatement extends Statement { @@ -35,14 +31,14 @@ class AlterStatement extends Statement * * @var AlterOperation[] */ - public $altered = array(); + public $altered = []; /** * Options of this statement. * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'ONLINE' => 1, 'OFFLINE' => 1, 'IGNORE' => 2, @@ -54,8 +50,8 @@ class AlterStatement extends Statement 'SERVER' => 3, 'TABLE' => 3, 'TABLESPACE' => 3, - 'VIEW' => 3 - ); + 'VIEW' => 3, + ]; /** * @param Parser $parser the instance that requests parsing @@ -75,10 +71,10 @@ class AlterStatement extends Statement $this->table = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); ++$list->idx; // Skipping field. @@ -114,7 +110,7 @@ class AlterStatement extends Statement } if ($state === 0) { - $options = array(); + $options = []; if ($this->options->has('DATABASE')) { $options = AlterOperation::$DB_OPTIONS; } elseif ($this->options->has('TABLE')) { @@ -138,7 +134,7 @@ class AlterStatement extends Statement */ public function build() { - $tmp = array(); + $tmp = []; foreach ($this->altered as $altered) { $tmp[] = $altered::build($altered); } diff --git a/src/Statements/AnalyzeStatement.php b/src/Statements/AnalyzeStatement.php index 4f6ea32..b14b891 100644 --- a/src/Statements/AnalyzeStatement.php +++ b/src/Statements/AnalyzeStatement.php @@ -1,8 +1,8 @@ <?php - /** * `ANALYZE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -12,12 +12,8 @@ use PhpMyAdmin\SqlParser\Statement; /** * `ANALYZE` statement. * - * ANALYZE array(NO_WRITE_TO_BINLOG | LOCAL] TABLE - * tbl_name array(, tbl_name] ... - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + * ANALYZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE + * tbl_name [, tbl_name] ... */ class AnalyzeStatement extends Statement { @@ -26,12 +22,12 @@ class AnalyzeStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, - 'LOCAL' => 3 - ); + 'LOCAL' => 3, + ]; /** * Analyzed tables. diff --git a/src/Statements/BackupStatement.php b/src/Statements/BackupStatement.php index 52f136b..3fab2de 100644 --- a/src/Statements/BackupStatement.php +++ b/src/Statements/BackupStatement.php @@ -1,19 +1,15 @@ <?php - /** * `BACKUP` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; /** * `BACKUP` statement. * - * BACKUP TABLE tbl_name array(, tbl_name] ... TO '/path/to/backup/directory' - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + * BACKUP TABLE tbl_name [, tbl_name] ... TO '/path/to/backup/directory' */ class BackupStatement extends MaintenanceStatement { @@ -22,15 +18,15 @@ class BackupStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, 'LOCAL' => 3, - 'TO' => array( + 'TO' => [ 4, 'var', - ) - ); + ], + ]; } diff --git a/src/Statements/CallStatement.php b/src/Statements/CallStatement.php index 00cb95c..6a3de69 100644 --- a/src/Statements/CallStatement.php +++ b/src/Statements/CallStatement.php @@ -1,8 +1,8 @@ <?php - /** * `CALL` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -17,10 +17,6 @@ use PhpMyAdmin\SqlParser\Statement; * or * * CALL sp_name[()] - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CallStatement extends Statement { @@ -38,6 +34,6 @@ class CallStatement extends Statement */ public function build() { - return "CALL " . $this->call->name . "(" . ($this->call->parameters ? implode(",", $this->call->parameters->raw) : "") . ")"; + return 'CALL ' . $this->call->name . '(' . ($this->call->parameters ? implode(',', $this->call->parameters->raw) : '') . ')'; } } diff --git a/src/Statements/CheckStatement.php b/src/Statements/CheckStatement.php index 57e5cb7..c112f0a 100644 --- a/src/Statements/CheckStatement.php +++ b/src/Statements/CheckStatement.php @@ -1,19 +1,15 @@ <?php - /** * `CHECK` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; /** * `CHECK` statement. * - * CHECK TABLE tbl_name array(, tbl_name] ... array(option] ... - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + * CHECK TABLE tbl_name [, tbl_name] ... [option] ... */ class CheckStatement extends MaintenanceStatement { @@ -22,7 +18,7 @@ class CheckStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'FOR UPGRADE' => 2, @@ -30,6 +26,6 @@ class CheckStatement extends MaintenanceStatement 'FAST' => 4, 'MEDIUM' => 5, 'EXTENDED' => 6, - 'CHANGED' => 7 - ); + 'CHANGED' => 7, + ]; } diff --git a/src/Statements/ChecksumStatement.php b/src/Statements/ChecksumStatement.php index 1be2588..259f287 100644 --- a/src/Statements/ChecksumStatement.php +++ b/src/Statements/ChecksumStatement.php @@ -1,19 +1,15 @@ <?php - /** * `CHECKSUM` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; /** * `CHECKSUM` statement. * - * CHECKSUM TABLE tbl_name array(, tbl_name] ... array( QUICK | EXTENDED ] - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + * CHECKSUM TABLE tbl_name [, tbl_name] ... [ QUICK | EXTENDED ] */ class ChecksumStatement extends MaintenanceStatement { @@ -22,10 +18,10 @@ class ChecksumStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'QUICK' => 2, - 'EXTENDED' => 3 - ); + 'EXTENDED' => 3, + ]; } diff --git a/src/Statements/CreateStatement.php b/src/Statements/CreateStatement.php index d3bf3bd..64ea57d 100644 --- a/src/Statements/CreateStatement.php +++ b/src/Statements/CreateStatement.php @@ -1,8 +1,8 @@ <?php - /** * `CREATE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -20,10 +20,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `CREATE` statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CreateStatement extends Statement { @@ -32,25 +28,25 @@ class CreateStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ // CREATE TABLE 'TEMPORARY' => 1, // CREATE VIEW 'OR REPLACE' => 2, - 'ALGORITHM' => array( + 'ALGORITHM' => [ 3, 'var=', - ), + ], // `DEFINER` is also used for `CREATE FUNCTION / PROCEDURE` - 'DEFINER' => array( + 'DEFINER' => [ 4, 'expr=', - ), - 'SQL SECURITY' => array( + ], + 'SQL SECURITY' => [ 5, 'var', - ), + ], 'DATABASE' => 6, 'EVENT' => 6, @@ -69,159 +65,159 @@ class CreateStatement extends Statement 'SCHEMA' => 6, // CREATE TABLE - 'IF NOT EXISTS' => 7 - ); + 'IF NOT EXISTS' => 7, + ]; /** * All database options. * * @var array */ - public static $DB_OPTIONS = array( - 'CHARACTER SET' => array( + public static $DB_OPTIONS = [ + 'CHARACTER SET' => [ 1, 'var=', - ), - 'CHARSET' => array( + ], + 'CHARSET' => [ 1, 'var=', - ), - 'DEFAULT CHARACTER SET' => array( + ], + 'DEFAULT CHARACTER SET' => [ 1, 'var=', - ), - 'DEFAULT CHARSET' => array( + ], + 'DEFAULT CHARSET' => [ 1, 'var=', - ), - 'DEFAULT COLLATE' => array( + ], + 'DEFAULT COLLATE' => [ 2, 'var=', - ), - 'COLLATE' => array( + ], + 'COLLATE' => [ 2, 'var=', - ) - ); + ], + ]; /** * All table options. * * @var array */ - public static $TABLE_OPTIONS = array( - 'ENGINE' => array( + public static $TABLE_OPTIONS = [ + 'ENGINE' => [ 1, 'var=', - ), - 'AUTO_INCREMENT' => array( + ], + 'AUTO_INCREMENT' => [ 2, 'var=', - ), - 'AVG_ROW_LENGTH' => array( + ], + 'AVG_ROW_LENGTH' => [ 3, 'var', - ), - 'CHARACTER SET' => array( + ], + 'CHARACTER SET' => [ 4, 'var=', - ), - 'CHARSET' => array( + ], + 'CHARSET' => [ 4, 'var=', - ), - 'DEFAULT CHARACTER SET' => array( + ], + 'DEFAULT CHARACTER SET' => [ 4, 'var=', - ), - 'DEFAULT CHARSET' => array( + ], + 'DEFAULT CHARSET' => [ 4, 'var=', - ), - 'CHECKSUM' => array( + ], + 'CHECKSUM' => [ 5, 'var', - ), - 'DEFAULT COLLATE' => array( + ], + 'DEFAULT COLLATE' => [ 6, 'var=', - ), - 'COLLATE' => array( + ], + 'COLLATE' => [ 6, 'var=', - ), - 'COMMENT' => array( + ], + 'COMMENT' => [ 7, 'var=', - ), - 'CONNECTION' => array( + ], + 'CONNECTION' => [ 8, 'var', - ), - 'DATA DIRECTORY' => array( + ], + 'DATA DIRECTORY' => [ 9, 'var', - ), - 'DELAY_KEY_WRITE' => array( + ], + 'DELAY_KEY_WRITE' => [ 10, 'var', - ), - 'INDEX DIRECTORY' => array( + ], + 'INDEX DIRECTORY' => [ 11, 'var', - ), - 'INSERT_METHOD' => array( + ], + 'INSERT_METHOD' => [ 12, 'var', - ), - 'KEY_BLOCK_SIZE' => array( + ], + 'KEY_BLOCK_SIZE' => [ 13, 'var', - ), - 'MAX_ROWS' => array( + ], + 'MAX_ROWS' => [ 14, 'var', - ), - 'MIN_ROWS' => array( + ], + 'MIN_ROWS' => [ 15, 'var', - ), - 'PACK_KEYS' => array( + ], + 'PACK_KEYS' => [ 16, 'var', - ), - 'PASSWORD' => array( + ], + 'PASSWORD' => [ 17, 'var', - ), - 'ROW_FORMAT' => array( + ], + 'ROW_FORMAT' => [ 18, 'var', - ), - 'TABLESPACE' => array( + ], + 'TABLESPACE' => [ 19, 'var', - ), - 'STORAGE' => array( + ], + 'STORAGE' => [ 20, 'var', - ), - 'UNION' => array( + ], + 'UNION' => [ 21, 'var', - ) - ); + ], + ]; /** * All function options. * * @var array */ - public static $FUNC_OPTIONS = array( - 'COMMENT' => array( + public static $FUNC_OPTIONS = [ + 'COMMENT' => [ 1, 'var=', - ), + ], 'LANGUAGE SQL' => 2, 'DETERMINISTIC' => 3, 'NOT DETERMINISTIC' => 3, @@ -229,24 +225,24 @@ class CreateStatement extends Statement 'NO SQL' => 4, 'READS SQL DATA' => 4, 'MODIFIES SQL DATA' => 4, - 'SQL SECURITY DEFINER' => array( + 'SQL SECURITY DEFINER' => [ 5, 'var', - ) - ); + ], + ]; /** * All trigger options. * * @var array */ - public static $TRIGGER_OPTIONS = array( + public static $TRIGGER_OPTIONS = [ 'BEFORE' => 1, 'AFTER' => 1, 'INSERT' => 2, 'UPDATE' => 2, - 'DELETE' => 2 - ); + 'DELETE' => 2, + ]; /** * The name of the entity that is created. @@ -262,11 +258,11 @@ class CreateStatement extends Statement * * Used by `CREATE TABLE`, `CREATE FUNCTION` and `CREATE PROCEDURE`. * - * @var OptionsArray - * * @see static::$TABLE_OPTIONS * @see static::$FUNC_OPTIONS * @see static::$TRIGGER_OPTIONS + * + * @var OptionsArray */ public $entityOptions; @@ -368,7 +364,7 @@ class CreateStatement extends Statement * * @var Token[]|string */ - public $body = array(); + public $body = []; /** * @return string @@ -389,12 +385,12 @@ class CreateStatement extends Statement . Expression::build($this->name) . ' ' . OptionsArray::build($this->entityOptions); } elseif ($this->options->has('TABLE')) { - if (! is_null($this->select)) { + if ($this->select !== null) { return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' ' . $this->select->build(); - } elseif (! is_null($this->like)) { + } elseif ($this->like !== null) { return 'CREATE ' . OptionsArray::build($this->options) . ' ' . Expression::build($this->name) . ' LIKE ' @@ -478,10 +474,10 @@ class CreateStatement extends Statement $this->name = Expression::parse( $parser, $list, - array( + [ 'parseField' => $fieldName, - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); if (! isset($this->name) || ($this->name === '')) { @@ -528,13 +524,13 @@ class CreateStatement extends Statement $this->like = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); // The 'LIKE' keyword was found, but no table_name was found next to it - if (is_null($this->like)) { + if ($this->like === null) { $parser->error( 'A table name was expected.', $list->tokens[$list->idx] @@ -626,7 +622,7 @@ class CreateStatement extends Statement } // Building the expression used for partitioning. - $this->$field .= ($token->type === Token::TYPE_WHITESPACE) ? ' ' : $token->token; + $this->$field .= $token->type === Token::TYPE_WHITESPACE ? ' ' : $token->token; // Last bracket was read, the expression ended. // Comparing with `0` and not `false`, because `false` means @@ -641,9 +637,9 @@ class CreateStatement extends Statement $this->partitions = ArrayObj::parse( $parser, $list, - array( - 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition' - ) + [ + 'type' => 'PhpMyAdmin\\SqlParser\\Components\\PartitionDefinition', + ] ); } break; @@ -657,10 +653,10 @@ class CreateStatement extends Statement if ($this->options->has('FUNCTION')) { $prev_token = $token; $token = $list->getNextOfType(Token::TYPE_KEYWORD); - if (is_null($token) || $token->keyword !== 'RETURNS') { + if ($token === null || $token->keyword !== 'RETURNS') { $parser->error( 'A "RETURNS" keyword was expected.', - is_null($token) ? $prev_token : $token + $token ?? $prev_token ); } else { ++$list->idx; @@ -718,10 +714,10 @@ class CreateStatement extends Statement $this->table = Expression::parse( $parser, $list, - array( + [ 'parseField' => 'table', - 'breakOnAlias' => true - ) + 'breakOnAlias' => true, + ] ); ++$list->idx; diff --git a/src/Statements/DeleteStatement.php b/src/Statements/DeleteStatement.php index 088489d..57e100b 100644 --- a/src/Statements/DeleteStatement.php +++ b/src/Statements/DeleteStatement.php @@ -1,8 +1,8 @@ <?php - /** * `DELETE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -41,11 +41,6 @@ use PhpMyAdmin\SqlParser\TokensList; * FROM tbl_name[.*] [, tbl_name[.*]] ... * USING table_references * [WHERE where_condition] - * - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class DeleteStatement extends Statement { @@ -54,11 +49,11 @@ class DeleteStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'QUICK' => 2, - 'IGNORE' => 3 - ); + 'IGNORE' => 3, + ]; /** * The clauses of this statement, in order. @@ -67,41 +62,41 @@ class DeleteStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'DELETE' => array( + public static $CLAUSES = [ + 'DELETE' => [ 'DELETE', 2, - ), + ], // Used for options. - '_OPTIONS' => array( + '_OPTIONS' => [ '_OPTIONS', 1, - ), - 'FROM' => array( + ], + 'FROM' => [ 'FROM', 3, - ), - 'PARTITION' => array( + ], + 'PARTITION' => [ 'PARTITION', 3, - ), - 'USING' => array( + ], + 'USING' => [ 'USING', 3, - ), - 'WHERE' => array( + ], + 'WHERE' => [ 'WHERE', 3, - ), - 'ORDER BY' => array( + ], + 'ORDER BY' => [ 'ORDER BY', 3, - ), - 'LIMIT' => array( + ], + 'LIMIT' => [ 'LIMIT', 3, - ) - ); + ], + ]; /** * Table(s) used as sources for this statement. @@ -166,25 +161,25 @@ class DeleteStatement extends Statement { $ret = 'DELETE ' . OptionsArray::build($this->options); - if (! is_null($this->columns) && count($this->columns) > 0) { + if ($this->columns !== null && count($this->columns) > 0) { $ret .= ' ' . ExpressionArray::build($this->columns); } - if (! is_null($this->from) && count($this->from) > 0) { + if ($this->from !== null && count($this->from) > 0) { $ret .= ' FROM ' . ExpressionArray::build($this->from); } - if (! is_null($this->join) && count($this->join) > 0) { + if ($this->join !== null && count($this->join) > 0) { $ret .= ' ' . JoinKeyword::build($this->join); } - if (! is_null($this->using) && count($this->using) > 0) { + if ($this->using !== null && count($this->using) > 0) { $ret .= ' USING ' . ExpressionArray::build($this->using); } - if (! is_null($this->where) && count($this->where) > 0) { + if ($this->where !== null && count($this->where) > 0) { $ret .= ' WHERE ' . Condition::build($this->where); } - if (! is_null($this->order) && count($this->order) > 0) { + if ($this->order !== null && count($this->order) > 0) { $ret .= ' ORDER BY ' . ExpressionArray::build($this->order); } - if (! is_null($this->limit) && strlen($this->limit) > 0) { + if ($this->limit !== null && strlen((string) $this->limit) > 0) { $ret .= ' LIMIT ' . Limit::build($this->limit); } diff --git a/src/Statements/DropStatement.php b/src/Statements/DropStatement.php index 7b9da2c..202d5e0 100644 --- a/src/Statements/DropStatement.php +++ b/src/Statements/DropStatement.php @@ -1,8 +1,8 @@ <?php - /** * `DROP` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -11,10 +11,6 @@ use PhpMyAdmin\SqlParser\Statement; /** * `DROP` statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class DropStatement extends Statement { @@ -23,7 +19,7 @@ class DropStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'DATABASE' => 1, 'EVENT' => 1, 'FUNCTION' => 1, @@ -39,8 +35,8 @@ class DropStatement extends Statement 'USER' => 1, 'TEMPORARY' => 2, - 'IF EXISTS' => 3 - ); + 'IF EXISTS' => 3, + ]; /** * The clauses of this statement, in order. @@ -49,26 +45,26 @@ class DropStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'DROP' => array( + public static $CLAUSES = [ + 'DROP' => [ 'DROP', 2, - ), + ], // Used for options. - '_OPTIONS' => array( + '_OPTIONS' => [ '_OPTIONS', 1, - ), + ], // Used for select expressions. - 'DROP_' => array( + 'DROP_' => [ 'DROP', 1, - ), - 'ON' => array( + ], + 'ON' => [ 'ON', 3, - ) - ); + ], + ]; /** * Dropped elements. diff --git a/src/Statements/ExplainStatement.php b/src/Statements/ExplainStatement.php index 96a5828..15e6add 100644 --- a/src/Statements/ExplainStatement.php +++ b/src/Statements/ExplainStatement.php @@ -1,17 +1,13 @@ <?php - /** * `EXPLAIN` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; /** * `EXPLAIN` statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ExplainStatement extends NotImplementedStatement { diff --git a/src/Statements/InsertStatement.php b/src/Statements/InsertStatement.php index 4e48c0d..6f63235 100644 --- a/src/Statements/InsertStatement.php +++ b/src/Statements/InsertStatement.php @@ -1,13 +1,13 @@ <?php - /** * `INSERT` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; -use PhpMyAdmin\SqlParser\Components\ArrayObj; use PhpMyAdmin\SqlParser\Components\Array2d; +use PhpMyAdmin\SqlParser\Components\ArrayObj; use PhpMyAdmin\SqlParser\Components\IntoKeyword; use PhpMyAdmin\SqlParser\Components\OptionsArray; use PhpMyAdmin\SqlParser\Components\SetOperation; @@ -48,10 +48,6 @@ use PhpMyAdmin\SqlParser\TokensList; * [ ON DUPLICATE KEY UPDATE * col_name=expr * [, col_name=expr] ... ] - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class InsertStatement extends Statement { @@ -60,12 +56,12 @@ class InsertStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'DELAYED' => 2, 'HIGH_PRIORITY' => 3, - 'IGNORE' => 4 - ); + 'IGNORE' => 4, + ]; /** * Tables used as target for this statement. @@ -113,15 +109,15 @@ class InsertStatement extends Statement $ret = 'INSERT ' . $this->options; $ret = trim($ret) . ' INTO ' . $this->into; - if (! is_null($this->values) && count($this->values) > 0) { + if ($this->values !== null && count($this->values) > 0) { $ret .= ' VALUES ' . Array2d::build($this->values); - } elseif (! is_null($this->set) && count($this->set) > 0) { + } elseif ($this->set !== null && count($this->set) > 0) { $ret .= ' SET ' . SetOperation::build($this->set); - } elseif (! is_null($this->select) && strlen($this->select) > 0) { + } elseif ($this->select !== null && strlen((string) $this->select) > 0) { $ret .= ' ' . $this->select->build(); } - if (! is_null($this->onDuplicateSet) && count($this->onDuplicateSet) > 0) { + if ($this->onDuplicateSet !== null && count($this->onDuplicateSet) > 0) { $ret .= ' ON DUPLICATE KEY UPDATE ' . SetOperation::build($this->onDuplicateSet); } @@ -195,7 +191,7 @@ class InsertStatement extends Statement $this->into = IntoKeyword::parse( $parser, $list, - array('fromInsert' => true) + ['fromInsert' => true] ); $state = 1; diff --git a/src/Statements/LoadStatement.php b/src/Statements/LoadStatement.php index 422efc7..62ef50f 100644 --- a/src/Statements/LoadStatement.php +++ b/src/Statements/LoadStatement.php @@ -1,8 +1,8 @@ <?php - /** * `LOAD` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -36,11 +36,6 @@ use PhpMyAdmin\SqlParser\TokensList; * [IGNORE number {LINES | ROWS}] * [(col_name_or_user_var,...)] * [SET col_name = expr,...] - * - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class LoadStatement extends Statement { @@ -49,48 +44,48 @@ class LoadStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, 'CONCURRENT' => 1, - 'LOCAL' => 2 - ); + 'LOCAL' => 2, + ]; /** * FIELDS/COLUMNS Options for `LOAD DATA...INFILE` statements. * * @var array */ - public static $FIELDS_OPTIONS = array( - 'TERMINATED BY' => array( + public static $FIELDS_OPTIONS = [ + 'TERMINATED BY' => [ 1, 'expr', - ), + ], 'OPTIONALLY' => 2, - 'ENCLOSED BY' => array( + 'ENCLOSED BY' => [ 3, 'expr', - ), - 'ESCAPED BY' => array( + ], + 'ESCAPED BY' => [ 4, 'expr', - ) - ); + ], + ]; /** * LINES Options for `LOAD DATA...INFILE` statements. * * @var array */ - public static $LINES_OPTIONS = array( - 'STARTING BY' => array( + public static $LINES_OPTIONS = [ + 'STARTING BY' => [ 1, 'expr', - ), - 'TERMINATED BY' => array( + ], + 'TERMINATED BY' => [ 2, 'expr', - ) - ); + ], + ]; /** * File name being used to load data. @@ -123,9 +118,9 @@ class LoadStatement extends Statement /** * Options for FIELDS/COLUMNS keyword. * - * @var OptionsArray - * * @see static::$FIELDS_OPTIONS + * + * @var OptionsArray */ public $fields_options; @@ -139,9 +134,9 @@ class LoadStatement extends Statement /** * Options for OPTIONS keyword. * - * @var OptionsArray - * * @see static::$LINES_OPTIONS + * + * @var OptionsArray */ public $lines_options; @@ -194,7 +189,7 @@ class LoadStatement extends Statement $ret .= ' INTO TABLE ' . $this->table; - if ($this->partition !== null && strlen($this->partition) > 0) { + if ($this->partition !== null && strlen((string) $this->partition) > 0) { $ret .= ' PARTITION ' . ArrayObj::build($this->partition); } @@ -206,7 +201,7 @@ class LoadStatement extends Statement $ret .= ' ' . $this->fields_keyword . ' ' . $this->fields_options; } - if ($this->lines_options !== null && strlen($this->lines_options) > 0) { + if ($this->lines_options !== null && strlen((string) $this->lines_options) > 0) { $ret .= ' LINES ' . $this->lines_options; } @@ -281,7 +276,7 @@ class LoadStatement extends Statement $this->file_name = Expression::parse( $parser, $list, - array('parseField' => 'file') + ['parseField' => 'file'] ); $state = 1; } elseif ($state === 1) { @@ -298,7 +293,7 @@ class LoadStatement extends Statement && $token->keyword === 'TABLE' ) { ++$list->idx; - $this->table = Expression::parse($parser, $list, array('parseField' => 'table')); + $this->table = Expression::parse($parser, $list, ['parseField' => 'table']); $state = 3; } else { $parser->error('Unexpected token.', $token); diff --git a/src/Statements/LockStatement.php b/src/Statements/LockStatement.php index d4c6cb1..6444586 100644 --- a/src/Statements/LockStatement.php +++ b/src/Statements/LockStatement.php @@ -1,8 +1,8 @@ <?php - /** * `LOCK` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * `LOCK` statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class LockStatement extends Statement { @@ -26,7 +22,7 @@ class LockStatement extends Statement * * @var LockExpression[] */ - public $locked = array(); + public $locked = []; /** * Whether it's a LOCK statement diff --git a/src/Statements/MaintenanceStatement.php b/src/Statements/MaintenanceStatement.php index ac3b8c9..273188f 100644 --- a/src/Statements/MaintenanceStatement.php +++ b/src/Statements/MaintenanceStatement.php @@ -1,8 +1,8 @@ <?php - /** * Maintenance statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -18,10 +18,6 @@ use PhpMyAdmin\SqlParser\TokensList; * * They follow the syntax: * STMT [some options] tbl_name [, tbl_name] ... [some more options] - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class MaintenanceStatement extends Statement { diff --git a/src/Statements/NotImplementedStatement.php b/src/Statements/NotImplementedStatement.php index e534cdf..dae6f85 100644 --- a/src/Statements/NotImplementedStatement.php +++ b/src/Statements/NotImplementedStatement.php @@ -1,8 +1,8 @@ <?php - /** * Not implemented (yet) statements. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -15,10 +15,6 @@ use PhpMyAdmin\SqlParser\TokensList; * Not implemented (yet) statements. * * The `after` function makes the parser jump straight to the first delimiter. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class NotImplementedStatement extends Statement { @@ -27,7 +23,7 @@ class NotImplementedStatement extends Statement * * @var Token[] */ - public $unknown = array(); + public $unknown = []; /** * @return string diff --git a/src/Statements/OptimizeStatement.php b/src/Statements/OptimizeStatement.php index 1aff056..c9c4979 100644 --- a/src/Statements/OptimizeStatement.php +++ b/src/Statements/OptimizeStatement.php @@ -1,8 +1,8 @@ <?php - /** * `OPTIMIZE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Statement; * * OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE * tbl_name [, tbl_name] ... - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class OptimizeStatement extends Statement { @@ -26,12 +22,12 @@ class OptimizeStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, - 'LOCAL' => 3 - ); + 'LOCAL' => 3, + ]; /** * Optimized tables. diff --git a/src/Statements/PurgeStatement.php b/src/Statements/PurgeStatement.php index 0374813..1f74f42 100644 --- a/src/Statements/PurgeStatement.php +++ b/src/Statements/PurgeStatement.php @@ -1,13 +1,12 @@ <?php - /** * `PURGE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; use PhpMyAdmin\SqlParser\Components\Expression; -use PhpMyAdmin\SqlParser\Components\OptionsArray; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Statement; use PhpMyAdmin\SqlParser\Token; @@ -18,10 +17,6 @@ use PhpMyAdmin\SqlParser\TokensList; * * PURGE { BINARY | MASTER } LOGS * { TO 'log_name' | BEFORE datetime_expr } - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class PurgeStatement extends Statement { @@ -51,7 +46,7 @@ class PurgeStatement extends Statement */ public function build() { - $ret = 'PURGE ' . $this->log_type . ' ' . 'LOGS ' + $ret = 'PURGE ' . $this->log_type . ' LOGS ' . ($this->end_option !== null ? ($this->end_option . ' ' . $this->end_expr) : ''); return trim($ret); } @@ -71,6 +66,7 @@ class PurgeStatement extends Statement */ $state = 0; + $prevToken = null; for (; $list->idx < $list->count; ++$list->idx) { /** * Token parsed at this moment. @@ -92,19 +88,19 @@ class PurgeStatement extends Statement switch ($state) { case 0: // parse `{ BINARY | MASTER }` - $this->log_type = self::parseExpectedKeyword($parser, $token, array('BINARY', 'MASTER')); + $this->log_type = self::parseExpectedKeyword($parser, $token, ['BINARY', 'MASTER']); break; case 1: // parse `LOGS` - self::parseExpectedKeyword($parser, $token, array('LOGS')); + self::parseExpectedKeyword($parser, $token, ['LOGS']); break; case 2: // parse `{ TO | BEFORE }` - $this->end_option = self::parseExpectedKeyword($parser, $token, array('TO', 'BEFORE')); + $this->end_option = self::parseExpectedKeyword($parser, $token, ['TO', 'BEFORE']); break; case 3: // parse `expr` - $this->end_expr = Expression::parse($parser, $list, array()); + $this->end_expr = Expression::parse($parser, $list, []); break; default: $parser->error('Unexpected token.', $token); diff --git a/src/Statements/RenameStatement.php b/src/Statements/RenameStatement.php index e1bcf0d..6e3d0ec 100644 --- a/src/Statements/RenameStatement.php +++ b/src/Statements/RenameStatement.php @@ -1,8 +1,8 @@ <?php - /** * `RENAME` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -17,10 +17,6 @@ use PhpMyAdmin\SqlParser\TokensList; * * RENAME TABLE tbl_name TO new_tbl_name * [, tbl_name2 TO new_tbl_name2] ... - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RenameStatement extends Statement { diff --git a/src/Statements/RepairStatement.php b/src/Statements/RepairStatement.php index fb76855..ee96e3b 100644 --- a/src/Statements/RepairStatement.php +++ b/src/Statements/RepairStatement.php @@ -1,8 +1,8 @@ <?php - /** * `REPAIR` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -12,10 +12,6 @@ namespace PhpMyAdmin\SqlParser\Statements; * REPAIR [NO_WRITE_TO_BINLOG | LOCAL] TABLE * tbl_name [, tbl_name] ... * [QUICK] [EXTENDED] [USE_FRM] - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RepairStatement extends MaintenanceStatement { @@ -24,7 +20,7 @@ class RepairStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, 'NO_WRITE_TO_BINLOG' => 2, @@ -32,6 +28,6 @@ class RepairStatement extends MaintenanceStatement 'QUICK' => 4, 'EXTENDED' => 5, - 'USE_FRM' => 6 - ); + 'USE_FRM' => 6, + ]; } diff --git a/src/Statements/ReplaceStatement.php b/src/Statements/ReplaceStatement.php index d912da0..132eef8 100644 --- a/src/Statements/ReplaceStatement.php +++ b/src/Statements/ReplaceStatement.php @@ -1,8 +1,8 @@ <?php - /** * `REPLACE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -35,10 +35,6 @@ use PhpMyAdmin\SqlParser\TokensList; * [PARTITION (partition_name,...)] * [(col_name,...)] * SELECT ... - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ReplaceStatement extends Statement { @@ -47,10 +43,10 @@ class ReplaceStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, - 'DELAYED' => 1 - ); + 'DELAYED' => 1, + ]; /** * Tables used as target for this statement. @@ -90,11 +86,11 @@ class ReplaceStatement extends Statement $ret = 'REPLACE ' . $this->options; $ret = trim($ret) . ' INTO ' . $this->into; - if (! is_null($this->values) && count($this->values) > 0) { + if ($this->values !== null && count($this->values) > 0) { $ret .= ' VALUES ' . Array2d::build($this->values); - } elseif (! is_null($this->set) && count($this->set) > 0) { + } elseif ($this->set !== null && count($this->set) > 0) { $ret .= ' SET ' . SetOperation::build($this->set); - } elseif (! is_null($this->select) && strlen($this->select) > 0) { + } elseif ($this->select !== null && strlen((string) $this->select) > 0) { $ret .= ' ' . $this->select->build(); } @@ -160,7 +156,7 @@ class ReplaceStatement extends Statement $this->into = IntoKeyword::parse( $parser, $list, - array('fromReplace' => true) + ['fromReplace' => true] ); $state = 1; diff --git a/src/Statements/RestoreStatement.php b/src/Statements/RestoreStatement.php index a7bf2c8..72b2ea2 100644 --- a/src/Statements/RestoreStatement.php +++ b/src/Statements/RestoreStatement.php @@ -1,8 +1,8 @@ <?php - /** * `RESTORE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -10,10 +10,6 @@ namespace PhpMyAdmin\SqlParser\Statements; * `RESTORE` statement. * * RESTORE TABLE tbl_name [, tbl_name] ... FROM '/path/to/backup/directory' - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class RestoreStatement extends MaintenanceStatement { @@ -22,12 +18,12 @@ class RestoreStatement extends MaintenanceStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'TABLE' => 1, - 'FROM' => array( + 'FROM' => [ 2, 'var', - ) - ); + ], + ]; } diff --git a/src/Statements/SelectStatement.php b/src/Statements/SelectStatement.php index 852dc0b..4fecd90 100644 --- a/src/Statements/SelectStatement.php +++ b/src/Statements/SelectStatement.php @@ -1,8 +1,8 @@ <?php - /** * `SELECT` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -33,10 +33,10 @@ use PhpMyAdmin\SqlParser\Statement; * [PARTITION partition_list] * [WHERE where_condition] * [GROUP BY {col_name | expr | position} - * [ASC | DESC), ... [WITH ROLLUP]] + * [ASC | DESC], ... [WITH ROLLUP]] * [HAVING where_condition] * [ORDER BY {col_name | expr | position} - * [ASC | DESC), ...] + * [ASC | DESC], ...] * [LIMIT {[offset,] row_count | row_count OFFSET offset}] * [PROCEDURE procedure_name(argument_list)] * [INTO OUTFILE 'file_name' @@ -45,10 +45,6 @@ use PhpMyAdmin\SqlParser\Statement; * | INTO DUMPFILE 'file_name' * | INTO var_name [, var_name]] * [FOR UPDATE | LOCK IN SHARE MODE]] - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class SelectStatement extends Statement { @@ -57,28 +53,28 @@ class SelectStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'ALL' => 1, 'DISTINCT' => 1, 'DISTINCTROW' => 1, 'HIGH_PRIORITY' => 2, - 'MAX_STATEMENT_TIME' => array( + 'MAX_STATEMENT_TIME' => [ 3, 'var=', - ), + ], 'STRAIGHT_JOIN' => 4, 'SQL_SMALL_RESULT' => 5, 'SQL_BIG_RESULT' => 6, 'SQL_BUFFER_RESULT' => 7, 'SQL_CACHE' => 8, 'SQL_NO_CACHE' => 8, - 'SQL_CALC_FOUND_ROWS' => 9 - ); + 'SQL_CALC_FOUND_ROWS' => 9, + ]; - public static $END_OPTIONS = array( + public static $END_OPTIONS = [ 'FOR UPDATE' => 1, - 'LOCK IN SHARE MODE' => 1 - ); + 'LOCK IN SHARE MODE' => 1, + ]; /** * The clauses of this statement, in order. @@ -87,153 +83,153 @@ class SelectStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'SELECT' => array( + public static $CLAUSES = [ + 'SELECT' => [ 'SELECT', 2, - ), + ], // Used for options. - '_OPTIONS' => array( + '_OPTIONS' => [ '_OPTIONS', 1, - ), + ], // Used for selected expressions. - '_SELECT' => array( + '_SELECT' => [ 'SELECT', 1, - ), - 'INTO' => array( + ], + 'INTO' => [ 'INTO', 3, - ), - 'FROM' => array( + ], + 'FROM' => [ 'FROM', 3, - ), - 'FORCE' => array( + ], + 'FORCE' => [ 'FORCE', 1, - ), - 'USE' => array( + ], + 'USE' => [ 'USE', 1, - ), - 'IGNORE' => array( + ], + 'IGNORE' => [ 'IGNORE', 3, - ), - 'PARTITION' => array( + ], + 'PARTITION' => [ 'PARTITION', 3, - ), + ], - 'JOIN' => array( + 'JOIN' => [ 'JOIN', 1, - ), - 'FULL JOIN' => array( + ], + 'FULL JOIN' => [ 'FULL JOIN', 1, - ), - 'INNER JOIN' => array( + ], + 'INNER JOIN' => [ 'INNER JOIN', 1, - ), - 'LEFT JOIN' => array( + ], + 'LEFT JOIN' => [ 'LEFT JOIN', 1, - ), - 'LEFT OUTER JOIN' => array( + ], + 'LEFT OUTER JOIN' => [ 'LEFT OUTER JOIN', 1, - ), - 'RIGHT JOIN' => array( + ], + 'RIGHT JOIN' => [ 'RIGHT JOIN', 1, - ), - 'RIGHT OUTER JOIN' => array( + ], + 'RIGHT OUTER JOIN' => [ 'RIGHT OUTER JOIN', 1, - ), - 'NATURAL JOIN' => array( + ], + 'NATURAL JOIN' => [ 'NATURAL JOIN', 1, - ), - 'NATURAL LEFT JOIN' => array( + ], + 'NATURAL LEFT JOIN' => [ 'NATURAL LEFT JOIN', 1, - ), - 'NATURAL RIGHT JOIN' => array( + ], + 'NATURAL RIGHT JOIN' => [ 'NATURAL RIGHT JOIN', 1, - ), - 'NATURAL LEFT OUTER JOIN' => array( + ], + 'NATURAL LEFT OUTER JOIN' => [ 'NATURAL LEFT OUTER JOIN', 1, - ), - 'NATURAL RIGHT OUTER JOIN' => array( + ], + 'NATURAL RIGHT OUTER JOIN' => [ 'NATURAL RIGHT JOIN', 1, - ), + ], - 'WHERE' => array( + 'WHERE' => [ 'WHERE', 3, - ), - 'GROUP BY' => array( + ], + 'GROUP BY' => [ 'GROUP BY', 3, - ), - 'HAVING' => array( + ], + 'HAVING' => [ 'HAVING', 3, - ), - 'ORDER BY' => array( + ], + 'ORDER BY' => [ 'ORDER BY', 3, - ), - 'LIMIT' => array( + ], + 'LIMIT' => [ 'LIMIT', 3, - ), - 'PROCEDURE' => array( + ], + 'PROCEDURE' => [ 'PROCEDURE', 3, - ), - 'UNION' => array( + ], + 'UNION' => [ 'UNION', 1, - ), - 'EXCEPT' => array( + ], + 'EXCEPT' => [ 'EXCEPT', 1, - ), - 'INTERSECT' => array( + ], + 'INTERSECT' => [ 'INTERSECT', 1, - ), - '_END_OPTIONS' => array( + ], + '_END_OPTIONS' => [ '_END_OPTIONS', 1, - ), + ], // These are available only when `UNION` is present. - // 'ORDER BY' => array('ORDER BY', 3), - // 'LIMIT' => array('LIMIT', 3) - ); + // 'ORDER BY' => ['ORDER BY', 3], + // 'LIMIT' => ['LIMIT', 3], + ]; /** * Expressions that are being selected by this statement. * * @var Expression[] */ - public $expr = array(); + public $expr = []; /** * Tables used as sources for this statement. * * @var Expression[] */ - public $from = array(); + public $from = []; /** * Index hints @@ -310,14 +306,14 @@ class SelectStatement extends Statement * * @var SelectStatement[] */ - public $union = array(); + public $union = []; /** * The end options of this query. * - * @var OptionsArray - * * @see static::$END_OPTIONS + * + * @var OptionsArray */ public $end_options; @@ -334,14 +330,14 @@ class SelectStatement extends Statement if (! empty($this->union)) { $clauses = static::$CLAUSES; unset($clauses['ORDER BY'], $clauses['LIMIT']); - $clauses['ORDER BY'] = array( + $clauses['ORDER BY'] = [ 'ORDER BY', - 3 - ); - $clauses['LIMIT'] = array( + 3, + ]; + $clauses['LIMIT'] = [ 'LIMIT', - 3 - ); + 3, + ]; return $clauses; } diff --git a/src/Statements/SetStatement.php b/src/Statements/SetStatement.php index d62b6f0..80a1dc7 100644 --- a/src/Statements/SetStatement.php +++ b/src/Statements/SetStatement.php @@ -1,8 +1,8 @@ <?php - /** * `SET` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -12,10 +12,6 @@ use PhpMyAdmin\SqlParser\Statement; /** * `SET` statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class SetStatement extends Statement { @@ -26,39 +22,39 @@ class SetStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'SET' => array( + public static $CLAUSES = [ + 'SET' => [ 'SET', - 3 - ), - '_END_OPTIONS' => array( + 3, + ], + '_END_OPTIONS' => [ '_END_OPTIONS', - 1 - ) - ); + 1, + ], + ]; /** * Possible exceptions in SET statment. * * @var array */ - public static $OPTIONS = array( - 'CHARSET' => array( + public static $OPTIONS = [ + 'CHARSET' => [ 3, 'var', - ), - 'CHARACTER SET' => array( + ], + 'CHARACTER SET' => [ 3, 'var', - ), - 'NAMES' => array( + ], + 'NAMES' => [ 3, 'var', - ), - 'PASSWORD' => array( + ], + 'PASSWORD' => [ 3, 'expr', - ), + ], 'SESSION' => 3, 'GLOBAL' => 3, 'PERSIST' => 3, @@ -67,15 +63,15 @@ class SetStatement extends Statement '@@GLOBAL' => 3, '@@PERSIST' => 3, '@@PERSIST_ONLY' => 3, - ); + ]; - public static $END_OPTIONS = array( - 'COLLATE' => array( + public static $END_OPTIONS = [ + 'COLLATE' => [ 1, 'var', - ), - 'DEFAULT' => 1 - ); + ], + 'DEFAULT' => 1, + ]; /** * Options used in current statement. @@ -87,9 +83,9 @@ class SetStatement extends Statement /** * The end options of this query. * - * @var OptionsArray - * * @see static::$END_OPTIONS + * + * @var OptionsArray */ public $end_options; diff --git a/src/Statements/ShowStatement.php b/src/Statements/ShowStatement.php index 1e9e67e..266b74e 100644 --- a/src/Statements/ShowStatement.php +++ b/src/Statements/ShowStatement.php @@ -1,17 +1,13 @@ <?php - /** * `SHOW` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; /** * `SHOW` statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ShowStatement extends NotImplementedStatement { @@ -20,7 +16,7 @@ class ShowStatement extends NotImplementedStatement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'CREATE' => 1, 'AUTHORS' => 2, 'BINARY' => 2, @@ -61,6 +57,6 @@ class ShowStatement extends NotImplementedStatement 'TRIGGERS' => 2, 'VARIABLES' => 2, 'VIEW' => 2, - 'WARNINGS' => 2 - ); + 'WARNINGS' => 2, + ]; } diff --git a/src/Statements/TransactionStatement.php b/src/Statements/TransactionStatement.php index 59bd9c6..f47f86f 100644 --- a/src/Statements/TransactionStatement.php +++ b/src/Statements/TransactionStatement.php @@ -1,8 +1,8 @@ <?php - /** * Transaction statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -13,10 +13,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Transaction statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class TransactionStatement extends Statement { @@ -60,7 +56,7 @@ class TransactionStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'START TRANSACTION' => 1, 'BEGIN' => 1, 'COMMIT' => 1, @@ -70,8 +66,8 @@ class TransactionStatement extends Statement 'AND NO CHAIN' => 3, 'AND CHAIN' => 3, 'RELEASE' => 4, - 'NO RELEASE' => 4 - ); + 'NO RELEASE' => 4, + ]; /** * @param Parser $parser the instance that requests parsing diff --git a/src/Statements/TruncateStatement.php b/src/Statements/TruncateStatement.php index 13a4d21..9397573 100644 --- a/src/Statements/TruncateStatement.php +++ b/src/Statements/TruncateStatement.php @@ -1,8 +1,8 @@ <?php - /** * `TRUNCATE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -11,10 +11,6 @@ use PhpMyAdmin\SqlParser\Statement; /** * `TRUNCATE` statement. - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class TruncateStatement extends Statement { @@ -23,9 +19,9 @@ class TruncateStatement extends Statement * * @var array */ - public static $OPTIONS = array( - 'TABLE' => 1 - ); + public static $OPTIONS = [ + 'TABLE' => 1, + ]; /** * The name of the truncated table. diff --git a/src/Statements/UpdateStatement.php b/src/Statements/UpdateStatement.php index da7d741..82adeb1 100644 --- a/src/Statements/UpdateStatement.php +++ b/src/Statements/UpdateStatement.php @@ -1,8 +1,8 @@ <?php - /** * `UPDATE` statement. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Statements; @@ -27,10 +27,6 @@ use PhpMyAdmin\SqlParser\Statement; * UPDATE [LOW_PRIORITY] [IGNORE] table_references * SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... * [WHERE where_condition] - * - * @category Statements - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class UpdateStatement extends Statement { @@ -39,10 +35,10 @@ class UpdateStatement extends Statement * * @var array */ - public static $OPTIONS = array( + public static $OPTIONS = [ 'LOW_PRIORITY' => 1, - 'IGNORE' => 2 - ); + 'IGNORE' => 2, + ]; /** * The clauses of this statement, in order. @@ -51,38 +47,38 @@ class UpdateStatement extends Statement * * @var array */ - public static $CLAUSES = array( - 'UPDATE' => array( + public static $CLAUSES = [ + 'UPDATE' => [ 'UPDATE', 2, - ), + ], // Used for options. - '_OPTIONS' => array( + '_OPTIONS' => [ '_OPTIONS', 1, - ), + ], // Used for updated tables. - '_UPDATE' => array( + '_UPDATE' => [ 'UPDATE', 1, - ), - 'SET' => array( + ], + 'SET' => [ 'SET', 3, - ), - 'WHERE' => array( + ], + 'WHERE' => [ 'WHERE', 3, - ), - 'ORDER BY' => array( + ], + 'ORDER BY' => [ 'ORDER BY', 3, - ), - 'LIMIT' => array( + ], + 'LIMIT' => [ 'LIMIT', 3, - ) - ); + ], + ]; /** * Tables used as sources for this statement. diff --git a/src/Token.php b/src/Token.php index f2f9860..23d1645 100644 --- a/src/Token.php +++ b/src/Token.php @@ -1,20 +1,16 @@ <?php - /** * Defines a token along with a set of types and flags and utility functions. * * An array of tokens will result after parsing the query. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; /** * A structure representing a lexeme that explicitly indicates its * categorization for the purpose of parsing. - * - * @category Tokens - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Token { @@ -215,8 +211,6 @@ class Token public $position; /** - * Constructor. - * * @param string $token the value of the token * @param int $type the type of the token * @param int $flags the flags of the token @@ -300,7 +294,7 @@ class Token // in PHP 5.3- the `null` parameter isn't handled correctly. $str = mb_substr( $str, - (! empty($str[1]) && ($str[1] === '@')) ? 2 : 1, + ! empty($str[1]) && ($str[1] === '@') ? 2 : 1, mb_strlen($str), 'UTF-8' ); @@ -330,16 +324,16 @@ class Token public function getInlineToken() { return str_replace( - array( + [ "\r", "\n", "\t", - ), - array( + ], + [ '\r', '\n', '\t', - ), + ], $this->token ); } diff --git a/src/TokensList.php b/src/TokensList.php index 4a3eec6..e8ff733 100644 --- a/src/TokensList.php +++ b/src/TokensList.php @@ -1,26 +1,24 @@ <?php - /** * Defines an array of tokens and utility functions to iterate through it. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; +use ArrayAccess; + /** * A structure representing a list of tokens. - * - * @category Tokens - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ -class TokensList implements \ArrayAccess +class TokensList implements ArrayAccess { /** * The array of tokens. * * @var array */ - public $tokens = array(); + public $tokens = []; /** * The count of tokens. @@ -37,12 +35,10 @@ class TokensList implements \ArrayAccess public $idx = 0; /** - * Constructor. - * * @param array $tokens the initial array of tokens * @param int $count the count of tokens in the initial array */ - public function __construct(array $tokens = array(), $count = -1) + public function __construct(array $tokens = [], $count = -1) { if (! empty($tokens)) { $this->tokens = $tokens; diff --git a/src/Translator.php b/src/Translator.php index 622bec9..36c519f 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -1,17 +1,19 @@ <?php - /** * Defines the localization helper infrastructure of the library. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; +use PhpMyAdmin\MoTranslator\Loader; + class Translator { /** * The MoTranslator loader object. * - * @var \PhpMyAdmin\MoTranslator\Loader + * @var Loader */ private static $loader; @@ -27,9 +29,9 @@ class Translator */ public static function load() { - if (is_null(self::$loader)) { + if (self::$loader === null) { // Create loader object - self::$loader = new \PhpMyAdmin\MoTranslator\Loader(); + self::$loader = new Loader(); // Set locale self::$loader->setlocale( @@ -43,7 +45,7 @@ class Translator self::$loader->bindtextdomain('sqlparser', __DIR__ . '/../locale/'); } - if (is_null(self::$translator)) { + if (self::$translator === null) { // Get translator self::$translator = self::$loader->getTranslator(); } diff --git a/src/UtfString.php b/src/UtfString.php index 5127b5b..cb4187c 100644 --- a/src/UtfString.php +++ b/src/UtfString.php @@ -1,5 +1,4 @@ <?php - /** * Implementation for UTF-8 strings. * @@ -10,19 +9,19 @@ * Because the lexer relies on the subscript operator this class had to be * implemented. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser; +use ArrayAccess; +use Exception; + /** * Implements array-like access for UTF-8 strings. * * In this library, this class should be used to parse UTF-8 queries. - * - * @category Misc - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ -class UtfString implements \ArrayAccess +class UtfString implements ArrayAccess { /** * The raw, multi-byte string. @@ -65,8 +64,6 @@ class UtfString implements \ArrayAccess public $charLen = 0; /** - * Constructor. - * * @param string $str the string */ public function __construct($str) @@ -141,11 +138,11 @@ class UtfString implements \ArrayAccess * @param int $offset the offset to be set * @param string $value the value to be set * - * @throws \Exception not implemented + * @throws Exception not implemented. */ public function offsetSet($offset, $value) { - throw new \Exception('Not implemented.'); + throw new Exception('Not implemented.'); } /** @@ -153,11 +150,11 @@ class UtfString implements \ArrayAccess * * @param int $offset the value to be unset * - * @throws \Exception not implemented + * @throws Exception not implemented. */ public function offsetUnset($offset) { - throw new \Exception('Not implemented.'); + throw new Exception('Not implemented.'); } /** @@ -167,10 +164,10 @@ class UtfString implements \ArrayAccess * However, this implementation supports UTF-8 characters containing up to 6 * bytes. * - * @param string $byte the byte to be analyzed - * * @see https://tools.ietf.org/html/rfc3629 * + * @param string $byte the byte to be analyzed + * * @return int */ public static function getCharLength($byte) diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php index 7361949..a2d6705 100644 --- a/src/Utils/BufferedQuery.php +++ b/src/Utils/BufferedQuery.php @@ -1,8 +1,8 @@ <?php - /** * Buffered query utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Context; * Implements a specialized lexer used to extract statements from large inputs * that are being buffered. After each statement has been extracted, a lexer or * a parser may be used. - * - * @category Lexer - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class BufferedQuery { @@ -49,7 +45,7 @@ class BufferedQuery * * @var array */ - public $options = array(); + public $options = []; /** * The last delimiter used. @@ -80,16 +76,14 @@ class BufferedQuery public $current = ''; /** - * Constructor. - * * @param string $query the query to be parsed * @param array $options the options of this parser */ - public function __construct($query = '', array $options = array()) + public function __construct($query = '', array $options = []) { // Merges specified options with defaults. $this->options = array_merge( - array( + [ /* * The starting delimiter. * @@ -111,7 +105,7 @@ class BufferedQuery * @var bool */ 'add_delimiter' => false, - ), + ], $options ); diff --git a/src/Utils/CLI.php b/src/Utils/CLI.php index d47af23..31eda8f 100644 --- a/src/Utils/CLI.php +++ b/src/Utils/CLI.php @@ -1,8 +1,8 @@ <?php - /** * CLI interface. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -12,10 +12,6 @@ use PhpMyAdmin\SqlParser\Parser; /** * CLI interface. - * - * @category Exceptions - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class CLI { @@ -42,11 +38,11 @@ class CLI public function parseHighlight() { - $longopts = array( + $longopts = [ 'help', 'query:', - 'format:' - ); + 'format:', + ]; $params = $this->getopt( 'hq:f:', $longopts @@ -58,7 +54,7 @@ class CLI if (! isset($params['f'])) { $params['f'] = 'cli'; } - if (! in_array($params['f'], array('html', 'cli', 'text'))) { + if (! in_array($params['f'], ['html', 'cli', 'text'])) { echo "ERROR: Invalid value for format!\n"; return false; @@ -78,7 +74,7 @@ class CLI return 0; } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -86,7 +82,7 @@ class CLI if (isset($params['q'])) { echo Formatter::format( $params['q'], - array('type' => $params['f']) + ['type' => $params['f']] ); echo "\n"; @@ -106,11 +102,11 @@ class CLI public function parseLint() { - $longopts = array( + $longopts = [ 'help', 'query:', - 'context:' - ); + 'context:', + ]; $params = $this->getopt( 'hq:c:', $longopts @@ -134,7 +130,7 @@ class CLI if (isset($params['c'])) { Context::load($params['c']); } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -142,7 +138,7 @@ class CLI if (isset($params['q'])) { $lexer = new Lexer($params['q'], false); $parser = new Parser($lexer->list); - $errors = Error::get(array($lexer, $parser)); + $errors = Error::get([$lexer, $parser]); if (count($errors) === 0) { return 0; } @@ -166,10 +162,10 @@ class CLI public function parseTokenize() { - $longopts = array( + $longopts = [ 'help', - 'query:' - ); + 'query:', + ]; $params = $this->getopt( 'hq:', $longopts @@ -190,7 +186,7 @@ class CLI return 0; } - if (!isset($params['q'])) { + if (! isset($params['q'])) { if ($stdIn = $this->readStdin()) { $params['q'] = $stdIn; } @@ -218,7 +214,8 @@ class CLI return 1; } - public function readStdin() { + public function readStdin() + { stream_set_blocking(STDIN, false); $stdin = stream_get_contents(STDIN); // restore-default block-mode setting diff --git a/src/Utils/Error.php b/src/Utils/Error.php index 20310a1..789da0e 100644 --- a/src/Utils/Error.php +++ b/src/Utils/Error.php @@ -1,20 +1,18 @@ <?php - /** * Error related utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; +use PhpMyAdmin\SqlParser\Exceptions\LexerException; +use PhpMyAdmin\SqlParser\Exceptions\ParserException; use PhpMyAdmin\SqlParser\Lexer; use PhpMyAdmin\SqlParser\Parser; /** * Error related utilities. - * - * @category Exceptions - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Error { @@ -28,30 +26,32 @@ class Error * `$err[1]` holds the error code. * `$err[2]` holds the string that caused the issue. * `$err[3]` holds the position of the string. - * (i.e. `array($msg, $code, $str, $pos)`) + * (i.e. `[$msg, $code, $str, $pos]`) */ public static function get($objs) { - $ret = array(); + $ret = []; foreach ($objs as $obj) { if ($obj instanceof Lexer) { + /** @var LexerException $err */ foreach ($obj->errors as $err) { - $ret[] = array( + $ret[] = [ $err->getMessage(), $err->getCode(), $err->ch, - $err->pos - ); + $err->pos, + ]; } } elseif ($obj instanceof Parser) { + /** @var ParserException $err */ foreach ($obj->errors as $err) { - $ret[] = array( + $ret[] = [ $err->getMessage(), $err->getCode(), $err->token->token, - $err->token->position - ); + $err->token->position, + ]; } } } @@ -77,7 +77,7 @@ class Error $errors, $format = '#%1$d: %2$s (near "%4$s" at position %5$d)' ) { - $ret = array(); + $ret = []; $i = 0; foreach ($errors as $key => $err) { @@ -86,7 +86,7 @@ class Error ++$i, $err[0], $err[1], - htmlspecialchars($err[2]), + htmlspecialchars((string) $err[2]), $err[3] ); } diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php index b608b73..017d5b1 100644 --- a/src/Utils/Formatter.php +++ b/src/Utils/Formatter.php @@ -1,8 +1,8 @@ <?php - /** * Utilities that are used for formatting queries. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Utilities that are used for formatting queries. - * - * @category Misc - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Formatter { @@ -46,10 +42,10 @@ class Formatter * * @var array */ - public static $SHORT_CLAUSES = array( + public static $SHORT_CLAUSES = [ 'CREATE' => true, - 'INSERT' => true - ); + 'INSERT' => true, + ]; /** * Clauses that must be inlined. @@ -58,7 +54,7 @@ class Formatter * * @var array */ - public static $INLINE_CLAUSES = array( + public static $INLINE_CLAUSES = [ 'CREATE' => true, 'INTO' => true, 'LIMIT' => true, @@ -66,15 +62,13 @@ class Formatter 'PARTITION' => true, 'PROCEDURE' => true, 'SUBPARTITION BY' => true, - 'VALUES' => true - ); + 'VALUES' => true, + ]; /** - * Constructor. - * * @param array $options the formatting options */ - public function __construct(array $options = array()) + public function __construct(array $options = []) { $this->options = $this->getMergedOptions($options); } @@ -99,11 +93,11 @@ class Formatter $options['formats'] = $this->getDefaultFormats(); } - if (is_null($options['line_ending'])) { + if ($options['line_ending'] === null) { $options['line_ending'] = $options['type'] === 'html' ? '<br/>' : "\n"; } - if (is_null($options['indentation'])) { + if ($options['indentation'] === null) { $options['indentation'] = $options['type'] === 'html' ? ' ' : ' '; } @@ -120,7 +114,7 @@ class Formatter */ protected function getDefaultOptions() { - return array( + return [ /* * The format of the result. * @@ -170,90 +164,90 @@ class Formatter * * @var bool */ - 'indent_parts' => true - ); + 'indent_parts' => true, + ]; } /** * The styles used for HTML formatting. - * array($type, $flags, $span, $callback). + * [$type, $flags, $span, $callback]. * * @return array */ protected function getDefaultFormats() { - return array( - array( + return [ + [ 'type' => Token::TYPE_KEYWORD, 'flags' => Token::FLAG_KEYWORD_RESERVED, 'html' => 'class="sql-reserved"', 'cli' => "\x1b[35m", 'function' => 'strtoupper', - ), - array( + ], + [ 'type' => Token::TYPE_KEYWORD, 'flags' => 0, 'html' => 'class="sql-keyword"', 'cli' => "\x1b[95m", 'function' => 'strtoupper', - ), - array( + ], + [ 'type' => Token::TYPE_COMMENT, 'flags' => 0, 'html' => 'class="sql-comment"', 'cli' => "\x1b[37m", 'function' => '', - ), - array( + ], + [ 'type' => Token::TYPE_BOOL, 'flags' => 0, 'html' => 'class="sql-atom"', 'cli' => "\x1b[36m", 'function' => 'strtoupper', - ), - array( + ], + [ 'type' => Token::TYPE_NUMBER, 'flags' => 0, 'html' => 'class="sql-number"', 'cli' => "\x1b[92m", 'function' => 'strtolower', - ), - array( + ], + [ 'type' => Token::TYPE_STRING, 'flags' => 0, 'html' => 'class="sql-string"', 'cli' => "\x1b[91m", 'function' => '', - ), - array( + ], + [ 'type' => Token::TYPE_SYMBOL, 'flags' => Token::FLAG_SYMBOL_PARAMETER, 'html' => 'class="sql-parameter"', 'cli' => "\x1b[31m", 'function' => '', - ), - array( + ], + [ 'type' => Token::TYPE_SYMBOL, 'flags' => 0, 'html' => 'class="sql-variable"', 'cli' => "\x1b[36m", 'function' => '', - ) - ); + ], + ]; } private static function mergeFormats(array $formats, array $newFormats) { - $added = array(); - $integers = array( + $added = []; + $integers = [ 'flags', - 'type' - ); - $strings = array( + 'type', + ]; + $strings = [ 'html', 'cli', - 'function' - ); + 'function', + ]; /* Sanitize the array so that we do not have to care later */ foreach ($newFormats as $j => $new) { @@ -341,7 +335,7 @@ class Formatter * * @var array */ - $blocksIndentation = array(); + $blocksIndentation = []; /** * A stack that keeps track of the line endings every time a new block @@ -349,7 +343,7 @@ class Formatter * * @var array */ - $blocksLineEndings = array(); + $blocksLineEndings = []; /** * Whether clause's options were formatted. @@ -437,7 +431,7 @@ class Formatter // Inline JOINs if (($prev->type === Token::TYPE_KEYWORD && isset(JoinKeyword::$JOINS[$prev->value])) - || (in_array($curr->value, array('ON', 'USING'), true) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 2]->value])) + || (in_array($curr->value, ['ON', 'USING'], true) && isset(JoinKeyword::$JOINS[$list->tokens[$list->idx - 2]->value])) || isset($list->tokens[$list->idx - 4], JoinKeyword::$JOINS[$list->tokens[$list->idx - 4]->value]) || isset($list->tokens[$list->idx - 6], JoinKeyword::$JOINS[$list->tokens[$list->idx - 6]->value]) ) { @@ -494,7 +488,7 @@ class Formatter // Finishing the line. if ($lineEnded) { $ret .= $this->options['line_ending'] - . str_repeat($this->options['indentation'], $indent); + . str_repeat($this->options['indentation'], (int) $indent); $lineEnded = false; } else { @@ -507,7 +501,7 @@ class Formatter // No space after . ( || ($curr->type === Token::TYPE_OPERATOR && ($curr->value === '.' || $curr->value === ',' || $curr->value === '(' || $curr->value === ')')) // No space before . , ( ) - || $curr->type === Token::TYPE_DELIMITER && mb_strlen($curr->value, 'UTF-8') < 2 + || $curr->type === Token::TYPE_DELIMITER && mb_strlen((string) $curr->value, 'UTF-8') < 2 ) ) { $ret .= ' '; @@ -529,7 +523,7 @@ class Formatter public function escapeConsole($string) { return str_replace( - array( + [ "\x00", "\x01", "\x02", @@ -562,8 +556,8 @@ class Formatter "\x1D", "\x1E", "\x1F", - ), - array( + ], + [ '\x00', '\x01', '\x02', @@ -596,7 +590,7 @@ class Formatter '\x1D', '\x1E', '\x1F', - ), + ], $string ); } @@ -663,7 +657,7 @@ class Formatter * * @return string the formatted string */ - public static function format($query, array $options = array()) + public static function format($query, array $options = []) { $lexer = new Lexer($query); $formatter = new self($options); @@ -713,7 +707,7 @@ class Formatter } // Keeping track of this group's length. - $length += mb_strlen($list->tokens[$idx]->value, 'UTF-8'); + $length += mb_strlen((string) $list->tokens[$idx]->value, 'UTF-8'); } return $length; diff --git a/src/Utils/Misc.php b/src/Utils/Misc.php index 7e6297f..6fcc831 100644 --- a/src/Utils/Misc.php +++ b/src/Utils/Misc.php @@ -1,8 +1,8 @@ <?php - /** * Miscellaneous utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -11,10 +11,6 @@ use PhpMyAdmin\SqlParser\Statements\SelectStatement; /** * Miscellaneous utilities. - * - * @category Misc - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Misc { @@ -32,12 +28,12 @@ class Misc || empty($statement->expr) || empty($statement->from) ) { - return array(); + return []; } - $retval = array(); + $retval = []; - $tables = array(); + $tables = []; /** * Expressions that may contain aliases. @@ -59,26 +55,26 @@ class Misc continue; } - $thisDb = (isset($expr->database) && ($expr->database !== '')) ? + $thisDb = isset($expr->database) && ($expr->database !== '') ? $expr->database : $database; if (! isset($retval[$thisDb])) { - $retval[$thisDb] = array( + $retval[$thisDb] = [ 'alias' => null, - 'tables' => array() - ); + 'tables' => [], + ]; } if (! isset($retval[$thisDb]['tables'][$expr->table])) { - $retval[$thisDb]['tables'][$expr->table] = array( - 'alias' => (isset($expr->alias) && ($expr->alias !== '')) ? + $retval[$thisDb]['tables'][$expr->table] = [ + 'alias' => isset($expr->alias) && ($expr->alias !== '') ? $expr->alias : null, - 'columns' => array() - ); + 'columns' => [], + ]; } if (! isset($tables[$thisDb])) { - $tables[$thisDb] = array(); + $tables[$thisDb] = []; } $tables[$thisDb][$expr->alias] = $expr->table; } @@ -89,7 +85,7 @@ class Misc continue; } - $thisDb = (isset($expr->database) && ($expr->database !== '')) ? + $thisDb = isset($expr->database) && ($expr->database !== '') ? $expr->database : $database; if (isset($expr->table) && ($expr->table !== '')) { diff --git a/src/Utils/Query.php b/src/Utils/Query.php index 9494d96..e16d172 100644 --- a/src/Utils/Query.php +++ b/src/Utils/Query.php @@ -1,8 +1,8 @@ <?php - /** * Statement utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -35,10 +35,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Statement utilities. - * - * @category Statement - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Query { @@ -47,7 +43,7 @@ class Query * * @var array */ - public static $FUNCTIONS = array( + public static $FUNCTIONS = [ 'SUM', 'AVG', 'STD', @@ -55,10 +51,10 @@ class Query 'MIN', 'MAX', 'BIT_OR', - 'BIT_AND' - ); + 'BIT_AND', + ]; - public static $ALLFLAGS = array( + public static $ALLFLAGS = [ /* * select ... DISTINCT ... */ @@ -211,8 +207,8 @@ class Query /* * ... UNION ... */ - 'union' => false - ); + 'union' => false, + ]; /** * Gets an array with flags select statement has. @@ -300,7 +296,7 @@ class Query */ public static function getFlags($statement, $all = false) { - $flags = array('querytype' => false); + $flags = ['querytype' => false]; if ($all) { $flags = self::$ALLFLAGS; } @@ -416,18 +412,18 @@ class Query $ret['statement'] = $statement; if ($statement instanceof SelectStatement) { - $ret['select_tables'] = array(); - $ret['select_expr'] = array(); + $ret['select_tables'] = []; + $ret['select_expr'] = []; // Finding tables' aliases and their associated real names. - $tableAliases = array(); + $tableAliases = []; foreach ($statement->from as $expr) { if (isset($expr->table, $expr->alias) && ($expr->table !== '') && ($expr->alias !== '') ) { - $tableAliases[$expr->alias] = array( + $tableAliases[$expr->alias] = [ $expr->table, - isset($expr->database) ? $expr->database : null - ); + isset($expr->database) ? $expr->database : null, + ]; } } @@ -439,11 +435,11 @@ class Query if (isset($tableAliases[$expr->table])) { $arr = $tableAliases[$expr->table]; } else { - $arr = array( + $arr = [ $expr->table, - (isset($expr->database) && ($expr->database !== '')) ? - $expr->database : null - ); + isset($expr->database) && ($expr->database !== '') ? + $expr->database : null, + ]; } if (! in_array($arr, $ret['select_tables'])) { $ret['select_tables'][] = $arr; @@ -459,11 +455,11 @@ class Query if (empty($ret['select_tables'])) { foreach ($statement->from as $expr) { if (isset($expr->table) && ($expr->table !== '')) { - $arr = array( + $arr = [ $expr->table, - (isset($expr->database) && ($expr->database !== '')) ? - $expr->database : null - ); + isset($expr->database) && ($expr->database !== '') ? + $expr->database : null, + ]; if (! in_array($arr, $ret['select_tables'])) { $ret['select_tables'][] = $arr; } @@ -484,12 +480,12 @@ class Query */ public static function getTables($statement) { - $expressions = array(); + $expressions = []; if (($statement instanceof InsertStatement) || ($statement instanceof ReplaceStatement) ) { - $expressions = array($statement->into->dest); + $expressions = [$statement->into->dest]; } elseif ($statement instanceof UpdateStatement) { $expressions = $statement->tables; } elseif (($statement instanceof SelectStatement) @@ -499,11 +495,11 @@ class Query } elseif (($statement instanceof AlterStatement) || ($statement instanceof TruncateStatement) ) { - $expressions = array($statement->table); + $expressions = [$statement->table]; } elseif ($statement instanceof DropStatement) { if (! $statement->options->has('TABLE')) { // No tables are dropped. - return array(); + return []; } $expressions = $statement->fields; } elseif ($statement instanceof RenameStatement) { @@ -512,7 +508,7 @@ class Query } } - $ret = array(); + $ret = []; foreach ($expressions as $expr) { if (! empty($expr->table)) { $expr->expr = null; // Force rebuild. @@ -698,7 +694,7 @@ class Query * @param Statement $statement the parsed query that has to be modified * @param TokensList $list the list of tokens * @param array $ops Clauses to be replaced. Contains multiple - * arrays having two values: array($old, $new). + * arrays having two values: [$old, $new]. * Clauses must be sorted. * * @return string @@ -796,11 +792,11 @@ class Query // No statement was found so we return the entire query as being the // remaining part. if (! $fullStatement) { - return array( + return [ null, $query, - $delimiter - ); + $delimiter, + ]; } // At least one query was found so we have to build the rest of the @@ -810,11 +806,11 @@ class Query $query .= $list->tokens[$list->idx]->token; } - return array( + return [ trim($statement), $query, - $delimiter - ); + $delimiter, + ]; } /** diff --git a/src/Utils/Routine.php b/src/Utils/Routine.php index 9b075dc..7c024c5 100644 --- a/src/Utils/Routine.php +++ b/src/Utils/Routine.php @@ -1,8 +1,8 @@ <?php - /** * Routine utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -14,10 +14,6 @@ use PhpMyAdmin\SqlParser\Statements\CreateStatement; /** * Routine utilities. - * - * @category Routines - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Routine { @@ -36,27 +32,27 @@ class Routine $type = DataType::parse(new Parser(), $lexer->list); if ($type === null) { - return array( + return [ + '', '', '', '', '', - '' - ); + ]; } - $options = array(); + $options = []; foreach ($type->options->options as $opt) { $options[] = is_string($opt) ? $opt : $opt['value']; } - return array( + return [ '', '', $type->name, implode(',', $type->parameters), - implode(' ', $options) - ); + implode(' ', $options), + ]; } /** @@ -74,29 +70,29 @@ class Routine $param = ParameterDefinition::parse(new Parser(), $lexer->list); if (empty($param[0])) { - return array( + return [ + '', '', '', '', '', - '' - ); + ]; } $param = $param[0]; - $options = array(); + $options = []; foreach ($param->type->options->options as $opt) { $options[] = is_string($opt) ? $opt : $opt['value']; } - return array( + return [ empty($param->inOut) ? '' : $param->inOut, $param->name, $param->type->name, implode(',', $param->type->parameters), - implode(' ', $options) - ); + implode(' ', $options), + ]; } /** @@ -108,15 +104,15 @@ class Routine */ public static function getParameters($statement) { - $retval = array( + $retval = [ 'num' => 0, - 'dir' => array(), - 'name' => array(), - 'type' => array(), - 'length' => array(), - 'length_arr' => array(), - 'opts' => array() - ); + 'dir' => [], + 'name' => [], + 'type' => [], + 'length' => [], + 'length_arr' => [], + 'opts' => [], + ]; if (! empty($statement->parameters)) { $idx = 0; @@ -126,7 +122,7 @@ class Routine $retval['type'][$idx] = $param->type->name; $retval['length'][$idx] = implode(',', $param->type->parameters); $retval['length_arr'][$idx] = $param->type->parameters; - $retval['opts'][$idx] = array(); + $retval['opts'][$idx] = []; foreach ($param->type->options->options as $opt) { $retval['opts'][$idx][] = is_string($opt) ? $opt : $opt['value']; diff --git a/src/Utils/Table.php b/src/Utils/Table.php index e73e430..168061d 100644 --- a/src/Utils/Table.php +++ b/src/Utils/Table.php @@ -1,8 +1,8 @@ <?php - /** * Table utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -10,10 +10,6 @@ use PhpMyAdmin\SqlParser\Statements\CreateStatement; /** * Table utilities. - * - * @category Statement - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Table { @@ -30,25 +26,25 @@ class Table || (! is_array($statement->fields)) || (! $statement->options->has('TABLE')) ) { - return array(); + return []; } - $ret = array(); + $ret = []; foreach ($statement->fields as $field) { if (empty($field->key) || ($field->key->type !== 'FOREIGN KEY')) { continue; } - $columns = array(); + $columns = []; foreach ($field->key->columns as $column) { $columns[] = $column['name']; } - $tmp = array( + $tmp = [ 'constraint' => $field->name, - 'index_list' => $columns - ); + 'index_list' => $columns, + ]; if (! empty($field->references)) { $tmp['ref_db_name'] = $field->references->table->database; @@ -87,10 +83,10 @@ class Table || (! is_array($statement->fields)) || (! $statement->options->has('TABLE')) ) { - return array(); + return []; } - $ret = array(); + $ret = []; foreach ($statement->fields as $field) { // Skipping keys. @@ -98,10 +94,10 @@ class Table continue; } - $ret[$field->name] = array( + $ret[$field->name] = [ 'type' => $field->type->name, - 'timestamp_not_null' => false - ); + 'timestamp_not_null' => false, + ]; if ($field->options) { if ($field->type->name === 'TIMESTAMP') { diff --git a/src/Utils/Tokens.php b/src/Utils/Tokens.php index 9166085..e823114 100644 --- a/src/Utils/Tokens.php +++ b/src/Utils/Tokens.php @@ -1,8 +1,8 @@ <?php - /** * Token utilities. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Utils; @@ -12,10 +12,6 @@ use PhpMyAdmin\SqlParser\TokensList; /** * Token utilities. - * - * @category Token - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class Tokens { @@ -44,7 +40,7 @@ class Tokens } if (isset($pattern['value_str']) - && strcasecmp($pattern['value_str'], $token->value) + && strcasecmp($pattern['value_str'], (string) $token->value) ) { return false; } @@ -85,7 +81,7 @@ class Tokens * * @var array */ - $newList = array(); + $newList = []; /** * The length of the find pattern is calculated only once. diff --git a/tests/Builder/AlterStatementTest.php b/tests/Builder/AlterStatementTest.php index 2372b6d..70236e4 100644 --- a/tests/Builder/AlterStatementTest.php +++ b/tests/Builder/AlterStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/CreateStatementTest.php b/tests/Builder/CreateStatementTest.php index 87c5a9b..fc24f16 100644 --- a/tests/Builder/CreateStatementTest.php +++ b/tests/Builder/CreateStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; @@ -114,19 +115,19 @@ class CreateStatementTest extends TestCase $stmt = new CreateStatement(); $stmt->name = new Expression('', 'test', ''); - $stmt->options = new OptionsArray(array('TABLE')); - $stmt->fields = array( + $stmt->options = new OptionsArray(['TABLE']); + $stmt->fields = [ new CreateDefinition( 'id', - new OptionsArray(array('NOT NULL', 'AUTO_INCREMENT')), - new DataType('INT', array(11), new OptionsArray(array('UNSIGNED'))) + new OptionsArray(['NOT NULL', 'AUTO_INCREMENT']), + new DataType('INT', [11], new OptionsArray(['UNSIGNED'])) ), new CreateDefinition( '', null, - new Key('', array(array('name' => 'id')), 'PRIMARY KEY') - ) - ); + new Key('', [['name' => 'id']], 'PRIMARY KEY') + ), + ]; $this->assertEquals( "CREATE TABLE `test` (\n" . @@ -217,8 +218,8 @@ class CreateStatementTest extends TestCase public function partitionQueries() { - return array( - array( + return [ + [ 'subparts' => <<<EOT CREATE TABLE `ts` ( `id` int(11) DEFAULT NULL, @@ -241,8 +242,9 @@ SUBPARTITION s5 ENGINE=InnoDB ) ) EOT - ), - array( + , + ], + [ 'parts' => <<<EOT CREATE TABLE ptest ( `event_date` date NOT NULL @@ -256,14 +258,15 @@ PARTITION p3 ENGINE=InnoDB, PARTITION p4 ENGINE=InnoDB ) EOT - ) - ); + , + ], + ]; } /** - * @dataProvider partitionQueries - * * @param string $query + * + * @dataProvider partitionQueries */ public function testBuilderPartitionsEngine($query) { @@ -304,9 +307,9 @@ EOT { $stmt = new CreateStatement(); - $stmt->options = new OptionsArray(array('TRIGGER')); + $stmt->options = new OptionsArray(['TRIGGER']); $stmt->name = new Expression('ins_sum'); - $stmt->entityOptions = new OptionsArray(array('BEFORE', 'INSERT')); + $stmt->entityOptions = new OptionsArray(['BEFORE', 'INSERT']); $stmt->table = new Expression('account'); $stmt->body = 'SET @sum = @sum + NEW.amount'; diff --git a/tests/Builder/DeleteStatementTest.php b/tests/Builder/DeleteStatementTest.php index 5aa037e..0327e03 100644 --- a/tests/Builder/DeleteStatementTest.php +++ b/tests/Builder/DeleteStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/ExplainStatementTest.php b/tests/Builder/ExplainStatementTest.php index 44bb817..7b6215f 100644 --- a/tests/Builder/ExplainStatementTest.php +++ b/tests/Builder/ExplainStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/InsertStatementTest.php b/tests/Builder/InsertStatementTest.php index 5e3360d..cf46143 100644 --- a/tests/Builder/InsertStatementTest.php +++ b/tests/Builder/InsertStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; @@ -64,7 +65,7 @@ class InsertStatementTest extends TestCase ); /* Assertion 6 */ - /* INSERT array(OPTIONS] INTO ... */ + /* INSERT [OPTIONS] INTO ... */ $parser = new Parser( 'INSERT DELAYED IGNORE INTO tbl SELECT * FROM bar' ); diff --git a/tests/Builder/LoadStatementTest.php b/tests/Builder/LoadStatementTest.php index 4c4e9b1..051e13d 100644 --- a/tests/Builder/LoadStatementTest.php +++ b/tests/Builder/LoadStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/LockStatementTest.php b/tests/Builder/LockStatementTest.php index b0b4d38..8593a87 100644 --- a/tests/Builder/LockStatementTest.php +++ b/tests/Builder/LockStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/PurgeStatementTest.php b/tests/Builder/PurgeStatementTest.php index caa1652..aae52b5 100644 --- a/tests/Builder/PurgeStatementTest.php +++ b/tests/Builder/PurgeStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/RenameStatementTest.php b/tests/Builder/RenameStatementTest.php index 97852ab..e803786 100644 --- a/tests/Builder/RenameStatementTest.php +++ b/tests/Builder/RenameStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/ReplaceStatementTest.php b/tests/Builder/ReplaceStatementTest.php index b1a6c91..ee5b95a 100644 --- a/tests/Builder/ReplaceStatementTest.php +++ b/tests/Builder/ReplaceStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/SelectStatementTest.php b/tests/Builder/SelectStatementTest.php index 6abee03..a22cf08 100644 --- a/tests/Builder/SelectStatementTest.php +++ b/tests/Builder/SelectStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; @@ -251,7 +252,8 @@ class SelectStatementTest extends TestCase ); } - public function testBuilderSurroundedByParanthesisWithLimit() { + public function testBuilderSurroundedByParanthesisWithLimit() + { $query = '(SELECT first_name FROM `actor` LIMIT 1, 2)'; $parser = new Parser($query); $stmt = $parser->statements[0]; diff --git a/tests/Builder/SetStatementTest.php b/tests/Builder/SetStatementTest.php index 771762e..2e1355d 100644 --- a/tests/Builder/SetStatementTest.php +++ b/tests/Builder/SetStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/StatementTest.php b/tests/Builder/StatementTest.php index 178901a..b75b5d5 100644 --- a/tests/Builder/StatementTest.php +++ b/tests/Builder/StatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; @@ -15,7 +16,7 @@ class StatementTest extends TestCase { $stmt = new SelectStatement(); - $stmt->options = new OptionsArray(array('DISTINCT')); + $stmt->options = new OptionsArray(['DISTINCT']); $stmt->expr[] = new Expression('sakila', 'film', 'film_id', 'fid'); $stmt->expr[] = new Expression('COUNT(film_id)'); diff --git a/tests/Builder/TransactionStatementTest.php b/tests/Builder/TransactionStatementTest.php index d7fd73c..5cd28c6 100644 --- a/tests/Builder/TransactionStatementTest.php +++ b/tests/Builder/TransactionStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Builder; diff --git a/tests/Builder/TruncateStatementTest.php b/tests/Builder/TruncateStatementTest.php index 09cd01f..1abee17 100644 --- a/tests/Builder/TruncateStatementTest.php +++ b/tests/Builder/TruncateStatementTest.php @@ -36,5 +36,4 @@ class TruncateStatementTest extends TestCase $this->assertEquals($query, $stmt->build()); } - } diff --git a/tests/Components/Array2dTest.php b/tests/Components/Array2dTest.php index 83e6215..1c57a43 100644 --- a/tests/Components/Array2dTest.php +++ b/tests/Components/Array2dTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -13,10 +14,10 @@ class Array2dTest extends TestCase $parser = new Parser(); $arrays = Array2d::parse($parser, $this->getTokensList('(1, 2) +')); $this->assertEquals( - array( + [ 1, 2, - ), + ], $arrays[0]->values ); } diff --git a/tests/Components/ArrayObjTest.php b/tests/Components/ArrayObjTest.php index 3664e1c..f683d72 100644 --- a/tests/Components/ArrayObjTest.php +++ b/tests/Components/ArrayObjTest.php @@ -1,8 +1,10 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; use PhpMyAdmin\SqlParser\Components\ArrayObj; +use PhpMyAdmin\SqlParser\Components\Expression; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Tests\TestCase; @@ -10,13 +12,13 @@ class ArrayObjTest extends TestCase { public function testBuildRaw() { - $component = new ArrayObj(array('a', 'b'), array()); + $component = new ArrayObj(['a', 'b'], []); $this->assertEquals('(a, b)', ArrayObj::build($component)); } public function testBuildValues() { - $component = new ArrayObj(array(), array('a', 'b')); + $component = new ArrayObj([], ['a', 'b']); $this->assertEquals('(a, b)', ArrayObj::build($component)); } @@ -25,21 +27,23 @@ class ArrayObjTest extends TestCase $components = ArrayObj::parse( new Parser(), $this->getTokensList('(1 + 2, 3 + 4)'), - array( - 'type' => 'PhpMyAdmin\\SqlParser\\Components\\Expression', - 'typeOptions' => array( + [ + 'type' => Expression::class, + 'typeOptions' => [ 'breakOnParentheses' => true, - ) - ) + ], + ] ); + $this->assertInstanceOf(Expression::class, $components[0]); + $this->assertInstanceOf(Expression::class, $components[1]); $this->assertEquals($components[0]->expr, '1 + 2'); $this->assertEquals($components[1]->expr, '3 + 4'); } /** - * @dataProvider parseProvider - * * @param mixed $test + * + * @dataProvider parseProvider */ public function testParse($test) { @@ -48,9 +52,9 @@ class ArrayObjTest extends TestCase public function parseProvider() { - return array( - array('parser/parseArrayErr1'), - array('parser/parseArrayErr3') - ); + return [ + ['parser/parseArrayErr1'], + ['parser/parseArrayErr3'], + ]; } } diff --git a/tests/Components/CaseExpressionTest.php b/tests/Components/CaseExpressionTest.php index b337cb1..2ea8f8b 100644 --- a/tests/Components/CaseExpressionTest.php +++ b/tests/Components/CaseExpressionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/ComponentTest.php b/tests/Components/ComponentTest.php index 13dbdf4..1044289 100644 --- a/tests/Components/ComponentTest.php +++ b/tests/Components/ComponentTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -6,26 +7,25 @@ use PhpMyAdmin\SqlParser\Component; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\Tests\TestCase; use PhpMyAdmin\SqlParser\TokensList; +use Throwable; class ComponentTest extends TestCase { /** - * @expectedException \Exception - * @expectedExceptionMessage Not implemented yet. * @runInSeparateProcess * @preserveGlobalState disabled */ public function testParse() { + $this->expectExceptionMessage('Not implemented yet.'); + $this->expectException(Throwable::class); Component::parse(new Parser(), new TokensList()); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Not implemented yet. - */ public function testBuild() { + $this->expectExceptionMessage('Not implemented yet.'); + $this->expectException(Throwable::class); Component::build(null); } } diff --git a/tests/Components/ConditionTest.php b/tests/Components/ConditionTest.php index 27c6a4f..eb8cca1 100644 --- a/tests/Components/ConditionTest.php +++ b/tests/Components/ConditionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/CreateDefinitionTest.php b/tests/Components/CreateDefinitionTest.php index d00feea..d0718c8 100644 --- a/tests/Components/CreateDefinitionTest.php +++ b/tests/Components/CreateDefinitionTest.php @@ -1,9 +1,11 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; use PhpMyAdmin\SqlParser\Components\CreateDefinition; use PhpMyAdmin\SqlParser\Parser; +use PhpMyAdmin\SqlParser\Statements\CreateStatement; use PhpMyAdmin\SqlParser\Tests\TestCase; class CreateDefinitionTest extends TestCase @@ -58,6 +60,7 @@ class CreateDefinitionTest extends TestCase 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' . ') ENGINE=InnoDB"' ); + $this->assertInstanceOf(CreateStatement::class, $parser->statements[0]); $this->assertEquals( 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE', CreateDefinition::build($parser->statements[0]->fields[1]) @@ -74,6 +77,7 @@ class CreateDefinitionTest extends TestCase 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE' . ') ENGINE=InnoDB"' ); + $this->assertInstanceOf(CreateStatement::class, $parser->statements[0]); $this->assertEquals( 'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE', CreateDefinition::build($parser->statements[0]->fields[2]) diff --git a/tests/Components/ExpressionArrayTest.php b/tests/Components/ExpressionArrayTest.php index f500f8a..597d0a3 100644 --- a/tests/Components/ExpressionArrayTest.php +++ b/tests/Components/ExpressionArrayTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -13,11 +14,11 @@ class ExpressionArrayTest extends TestCase $component = ExpressionArray::parse( new Parser(), $this->getTokensList('(expr)'), - array( - 'breakOnParentheses' => true - ) + [ + 'breakOnParentheses' => true, + ] ); - $this->assertEquals(array(), $component); + $this->assertEquals([], $component); } public function testParse2() @@ -25,9 +26,9 @@ class ExpressionArrayTest extends TestCase $component = ExpressionArray::parse( new Parser(), $this->getTokensList('(expr) +'), - array( - 'parenthesesDelimited' => true - ) + [ + 'parenthesesDelimited' => true, + ] ); $this->assertCount(1, $component); $this->assertEquals('(expr)', $component[0]->expr); diff --git a/tests/Components/ExpressionTest.php b/tests/Components/ExpressionTest.php index 45b8be5..8e51e01 100644 --- a/tests/Components/ExpressionTest.php +++ b/tests/Components/ExpressionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -21,10 +22,10 @@ class ExpressionTest extends TestCase } /** - * @dataProvider parseErrProvider - * * @param mixed $expr * @param mixed $error + * + * @dataProvider parseErrProvider */ public function testParseErr($expr, $error) { @@ -36,38 +37,38 @@ class ExpressionTest extends TestCase public function parseErrProvider() { - return array( + return [ /* - array( + [ '(1))', 'Unexpected closing bracket.', - ), + ], */ - array( + [ 'tbl..col', 'Unexpected dot.', - ), - array( + ], + [ 'id AS AS id2', 'An alias was expected.', - ), - array( + ], + [ 'id`id2`\'id3\'', 'An alias was previously found.', - ), - array( + ], + [ '(id) id2 id3', 'An alias was previously found.', - ) - ); + ], + ]; } public function testBuild() { - $component = array( + $component = [ new Expression('1 + 2', 'three'), - new Expression('1 + 3', 'four') - ); + new Expression('1 + 3', 'four'), + ]; $this->assertEquals( Expression::build($component), '1 + 2 AS `three`, 1 + 3 AS `four`' diff --git a/tests/Components/FunctionCallTest.php b/tests/Components/FunctionCallTest.php index b8b485a..386b220 100644 --- a/tests/Components/FunctionCallTest.php +++ b/tests/Components/FunctionCallTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -10,13 +11,13 @@ class FunctionCallTest extends TestCase { public function testBuildArray() { - $component = new FunctionCall('func', array('a', 'b')); + $component = new FunctionCall('func', ['a', 'b']); $this->assertEquals('func(a, b)', FunctionCall::build($component)); } public function testBuildArrayObj() { - $component = new FunctionCall('func', new ArrayObj(array('a', 'b'))); + $component = new FunctionCall('func', new ArrayObj(['a', 'b'])); $this->assertEquals('func(a, b)', FunctionCall::build($component)); } } diff --git a/tests/Components/GroupKeywordTest.php b/tests/Components/GroupKeywordTest.php index 8d4a407..41ff89a 100644 --- a/tests/Components/GroupKeywordTest.php +++ b/tests/Components/GroupKeywordTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -12,11 +13,11 @@ class GroupKeywordTest extends TestCase { $this->assertEquals( GroupKeyword::build( - array( + [ new GroupKeyword(new Expression('a')), new GroupKeyword(new Expression('b')), new GroupKeyword(new Expression('c')), - ) + ] ), 'a, b, c' ); diff --git a/tests/Components/IntoKeywordTest.php b/tests/Components/IntoKeywordTest.php index 2ebf5ee..896c363 100644 --- a/tests/Components/IntoKeywordTest.php +++ b/tests/Components/IntoKeywordTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/JoinKeywordTest.php b/tests/Components/JoinKeywordTest.php index 8baf93f..91fd4a6 100644 --- a/tests/Components/JoinKeywordTest.php +++ b/tests/Components/JoinKeywordTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -23,7 +24,7 @@ class JoinKeywordTest extends TestCase $this->assertCount(1, $component); $this->assertEquals('table2', $component[0]->expr->expr); $this->assertNull($component[0]->on); - $this->assertEquals(array('id'), $component[0]->using->values); + $this->assertEquals(['id'], $component[0]->using->values); } public function testBuild() diff --git a/tests/Components/KeyTest.php b/tests/Components/KeyTest.php index c27b9d8..aeb403d 100644 --- a/tests/Components/KeyTest.php +++ b/tests/Components/KeyTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/LimitTest.php b/tests/Components/LimitTest.php index 9e00a65..18e7461 100644 --- a/tests/Components/LimitTest.php +++ b/tests/Components/LimitTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -20,9 +21,9 @@ class LimitTest extends TestCase } /** - * @dataProvider parseProvider - * * @param mixed $test + * + * @dataProvider parseProvider */ public function testParse($test) { @@ -31,9 +32,9 @@ class LimitTest extends TestCase public function parseProvider() { - return array( - array('parser/parseLimitErr1'), - array('parser/parseLimitErr2') - ); + return [ + ['parser/parseLimitErr1'], + ['parser/parseLimitErr2'], + ]; } } diff --git a/tests/Components/LockExpressionTest.php b/tests/Components/LockExpressionTest.php index 00d5ffb..2fc86bd 100644 --- a/tests/Components/LockExpressionTest.php +++ b/tests/Components/LockExpressionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -26,10 +27,10 @@ class LockExpressionTest extends TestCase } /** - * @dataProvider parseErrProvider - * * @param mixed $expr * @param mixed $error + * + * @dataProvider parseErrProvider */ public function testParseErr($expr, $error) { @@ -41,28 +42,28 @@ class LockExpressionTest extends TestCase public function parseErrProvider() { - return array( - array( + return [ + [ 'table1 AS t1', 'Unexpected end of LOCK expression.', - ), - array( + ], + [ 'table1 AS t1 READ WRITE', 'Unexpected keyword.', - ), - array( + ], + [ 'table1 AS t1 READ 2', 'Unexpected token.', - ) - ); + ], + ]; } public function testBuild() { - $component = array( + $component = [ LockExpression::parse(new Parser(), $this->getTokensList('table1 AS t1 READ LOCAL')), - LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE')) - ); + LockExpression::parse(new Parser(), $this->getTokensList('table2 LOW_PRIORITY WRITE')), + ]; $this->assertEquals( LockExpression::build($component), 'table1 AS `t1` READ LOCAL, table2 LOW_PRIORITY WRITE' diff --git a/tests/Components/OptionsArrayTest.php b/tests/Components/OptionsArrayTest.php index a642f83..3904fdf 100644 --- a/tests/Components/OptionsArrayTest.php +++ b/tests/Components/OptionsArrayTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -13,26 +14,26 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('A B = /*comment*/ (test) C'), - array( + [ 'A' => 1, - 'B' => array( + 'B' => [ 2, 'var', - ), - 'C' => 3 - ) + ], + 'C' => 3, + ] ); $this->assertEquals( - array( + [ 1 => 'A', - 2 => array( + 2 => [ 'name' => 'B', 'expr' => '(test)', 'value' => 'test', 'equals' => true, - ), + ], 3 => 'C', - ), + ], $component->options ); } @@ -42,17 +43,17 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('SUM = (3 + 5) RESULT = 8'), - array( - 'SUM' => array( + [ + 'SUM' => [ 1, 'expr', - array('parenthesesDelimited' => true), - ), - 'RESULT' => array( + ['parenthesesDelimited' => true], + ], + 'RESULT' => [ 2, 'var', - ) - ) + ], + ] ); $this->assertEquals('(3 + 5)', (string) $component->has('SUM', true)); $this->assertEquals('8', $component->has('RESULT')); @@ -63,14 +64,14 @@ class OptionsArrayTest extends TestCase $component = OptionsArray::parse( new Parser(), $this->getTokensList('A B = /*comment*/ (test) C'), - array( + [ 'A' => 1, - 'B' => array( + 'B' => [ 2, 'var', - ), - 'C' => 3 - ) + ], + 'C' => 3, + ] ); $this->assertTrue($component->has('A')); $this->assertEquals('test', $component->has('B')); @@ -81,23 +82,23 @@ class OptionsArrayTest extends TestCase public function testRemove() { /* Assertion 1 */ - $component = new OptionsArray(array('a', 'b', 'c')); + $component = new OptionsArray(['a', 'b', 'c']); $this->assertTrue($component->remove('b')); $this->assertFalse($component->remove('d')); - $this->assertEquals($component->options, array(0 => 'a', 2 => 'c')); + $this->assertEquals($component->options, [0 => 'a', 2 => 'c']); /* Assertion 2 */ $component = OptionsArray::parse( new Parser(), $this->getTokensList('A B = /*comment*/ (test) C'), - array( + [ 'A' => 1, - 'B' => array( + 'B' => [ 2, 'var', - ), - 'C' => 3 - ) + ], + 'C' => 3, + ] ); $this->assertEquals('test', $component->has('B')); $component->remove('B'); @@ -106,23 +107,23 @@ class OptionsArrayTest extends TestCase public function testMerge() { - $component = new OptionsArray(array('a')); - $component->merge(array('b', 'c')); - $this->assertEquals($component->options, array('a', 'b', 'c')); + $component = new OptionsArray(['a']); + $component->merge(['b', 'c']); + $this->assertEquals($component->options, ['a', 'b', 'c']); } public function testBuild() { $component = new OptionsArray( - array( + [ 'ALL', 'SQL_CALC_FOUND_ROWS', - array( + [ 'name' => 'MAX_STATEMENT_TIME', 'value' => '42', 'equals' => true, - ), - ) + ], + ] ); $this->assertEquals( OptionsArray::build($component), diff --git a/tests/Components/OrderKeywordTest.php b/tests/Components/OrderKeywordTest.php index bc07d03..11468fb 100644 --- a/tests/Components/OrderKeywordTest.php +++ b/tests/Components/OrderKeywordTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -12,10 +13,10 @@ class OrderKeywordTest extends TestCase { $this->assertEquals( OrderKeyword::build( - array( + [ new OrderKeyword(new Expression('a'), 'ASC'), - new OrderKeyword(new Expression('b'), 'DESC') - ) + new OrderKeyword(new Expression('b'), 'DESC'), + ] ), 'a ASC, b DESC' ); diff --git a/tests/Components/ParameterDefinitionTest.php b/tests/Components/ParameterDefinitionTest.php index 683eb3a..38d28e0 100644 --- a/tests/Components/ParameterDefinitionTest.php +++ b/tests/Components/ParameterDefinitionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/PartitionDefinitionTest.php b/tests/Components/PartitionDefinitionTest.php index 3c9a847..2d26076 100644 --- a/tests/Components/PartitionDefinitionTest.php +++ b/tests/Components/PartitionDefinitionTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Components/ReferenceTest.php b/tests/Components/ReferenceTest.php index dc142fe..19768c7 100644 --- a/tests/Components/ReferenceTest.php +++ b/tests/Components/ReferenceTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; @@ -13,12 +14,12 @@ class ReferenceTest extends TestCase { $component = Reference::parse(new Parser(), $this->getTokensList('tbl (id)')); $this->assertEquals('tbl', $component->table->table); - $this->assertEquals(array('id'), $component->columns); + $this->assertEquals(['id'], $component->columns); } public function testBuild() { - $component = new Reference(new Expression('`tbl`'), array('id')); + $component = new Reference(new Expression('`tbl`'), ['id']); $this->assertEquals('`tbl` (`id`)', Reference::build($component)); } } diff --git a/tests/Components/RenameOperationTest.php b/tests/Components/RenameOperationTest.php index 919c4bd..6f38605 100644 --- a/tests/Components/RenameOperationTest.php +++ b/tests/Components/RenameOperationTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Components; diff --git a/tests/Lexer/ContextTest.php b/tests/Lexer/ContextTest.php index 980eecd..2a9c8f3 100644 --- a/tests/Lexer/ContextTest.php +++ b/tests/Lexer/ContextTest.php @@ -1,9 +1,11 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Lexer; use PhpMyAdmin\SqlParser\Context; use PhpMyAdmin\SqlParser\Tests\TestCase; +use Throwable; class ContextTest extends TestCase { @@ -29,7 +31,7 @@ class ContextTest extends TestCase public function testLoadClosest($context, $expected) { $this->assertEquals($expected, Context::loadClosest($context)); - if (! is_null($expected)) { + if ($expected !== null) { $this->assertEquals('\\PhpMyAdmin\\SqlParser\\Contexts\\Context' . $expected, Context::$loadedContext); $this->assertTrue(class_exists(Context::$loadedContext)); } @@ -40,42 +42,42 @@ class ContextTest extends TestCase public function contextLoading() { - return array( - 'MySQL match' => array( + return [ + 'MySQL match' => [ 'MySql50500', 'MySql50500', - ), - 'MySQL strip' => array( + ], + 'MySQL strip' => [ 'MySql50712', 'MySql50700', - ), - 'MySQL fallback' => array( + ], + 'MySQL fallback' => [ 'MySql99999', 'MySql50700', - ), - 'MariaDB match' => array( + ], + 'MariaDB match' => [ 'MariaDb100000', 'MariaDb100000', - ), - 'MariaDB stripg' => array( + ], + 'MariaDB stripg' => [ 'MariaDb109900', 'MariaDb100000', - ), - 'MariaDB fallback' => array( + ], + 'MariaDB fallback' => [ 'MariaDb990000', 'MariaDb100300', - ), - 'Invalid' => array( + ], + 'Invalid' => [ 'Sql', null, - ) - ); + ], + ]; } /** - * @dataProvider contextNames - * * @param mixed $context + * + * @dataProvider contextNames */ public function testLoadAll($context) { @@ -88,26 +90,24 @@ class ContextTest extends TestCase public function contextNames() { - return array( - array('MySql50000'), - array('MySql50100'), - array('MySql50500'), - array('MySql50600'), - array('MySql50700'), - array('MySql80000'), - array('MariaDb100000'), - array('MariaDb100100'), - array('MariaDb100200'), - array('MariaDb100300') - ); + return [ + ['MySql50000'], + ['MySql50100'], + ['MySql50500'], + ['MySql50600'], + ['MySql50700'], + ['MySql80000'], + ['MariaDb100000'], + ['MariaDb100100'], + ['MariaDb100200'], + ['MariaDb100300'], + ]; } - /** - * @expectedException \Exception - * @expectedExceptionMessage Specified context ("\PhpMyAdmin\SqlParser\Contexts\ContextFoo") does not exist. - */ public function testLoadError() { + $this->expectExceptionMessage('Specified context ("\PhpMyAdmin\SqlParser\Contexts\ContextFoo") does not exist.'); + $this->expectException(Throwable::class); Context::load('Foo'); } @@ -139,11 +139,11 @@ class ContextTest extends TestCase $this->assertEquals('`test`', Context::escape('test')); $this->assertEquals( - array( + [ '`a`', '`b`', - ), - Context::escape(array('a', 'b')) + ], + Context::escape(['a', 'b']) ); } } diff --git a/tests/Lexer/IsMethodsTest.php b/tests/Lexer/IsMethodsTest.php index 3a7ef9b..e967514 100644 --- a/tests/Lexer/IsMethodsTest.php +++ b/tests/Lexer/IsMethodsTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Lexer; diff --git a/tests/Lexer/LexerTest.php b/tests/Lexer/LexerTest.php index 7bc2da5..92a8667 100644 --- a/tests/Lexer/LexerTest.php +++ b/tests/Lexer/LexerTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Lexer; @@ -26,20 +27,18 @@ class LexerTest extends TestCase $this->assertEquals( $lexer->errors, - array( + [ new LexerException('error #1', 'foo', 1, 2), new LexerException('error #2', 'bar', 3, 4), - ) + ] ); } - /** - * @expectedException \PhpMyAdmin\SqlParser\Exceptions\LexerException - * @expectedExceptionMessage strict error - * @expectedExceptionCode 4 - */ public function testErrorStrict() { + $this->expectExceptionCode(4); + $this->expectExceptionMessage('strict error'); + $this->expectException(LexerException::class); $lexer = new Lexer(''); $lexer->strict = true; @@ -47,9 +46,9 @@ class LexerTest extends TestCase } /** - * @dataProvider lexProvider - * * @param mixed $test + * + * @dataProvider lexProvider */ public function testLex($test) { @@ -58,33 +57,33 @@ class LexerTest extends TestCase public function lexProvider() { - return array( - array('lexer/lex'), - array('lexer/lexUtf8'), - array('lexer/lexBool'), - array('lexer/lexComment'), - array('lexer/lexCommentEnd'), - array('lexer/lexDelimiter'), - array('lexer/lexDelimiter2'), - array('lexer/lexDelimiterErr1'), - array('lexer/lexDelimiterErr2'), - array('lexer/lexDelimiterErr3'), - array('lexer/lexDelimiterLen'), - array('lexer/lexKeyword'), - array('lexer/lexKeyword2'), - array('lexer/lexNumber'), - array('lexer/lexOperator'), - array('lexer/lexString'), - array('lexer/lexStringErr1'), - array('lexer/lexSymbol'), - array('lexer/lexSymbolErr1'), - array('lexer/lexSymbolErr2'), - array('lexer/lexSymbolErr3'), - array('lexer/lexSymbolUser'), - array('lexer/lexWhitespace'), - array('lexer/lexLabel1'), - array('lexer/lexLabel2'), - array('lexer/lexNoLabel') - ); + return [ + ['lexer/lex'], + ['lexer/lexUtf8'], + ['lexer/lexBool'], + ['lexer/lexComment'], + ['lexer/lexCommentEnd'], + ['lexer/lexDelimiter'], + ['lexer/lexDelimiter2'], + ['lexer/lexDelimiterErr1'], + ['lexer/lexDelimiterErr2'], + ['lexer/lexDelimiterErr3'], + ['lexer/lexDelimiterLen'], + ['lexer/lexKeyword'], + ['lexer/lexKeyword2'], + ['lexer/lexNumber'], + ['lexer/lexOperator'], + ['lexer/lexString'], + ['lexer/lexStringErr1'], + ['lexer/lexSymbol'], + ['lexer/lexSymbolErr1'], + ['lexer/lexSymbolErr2'], + ['lexer/lexSymbolErr3'], + ['lexer/lexSymbolUser'], + ['lexer/lexWhitespace'], + ['lexer/lexLabel1'], + ['lexer/lexLabel2'], + ['lexer/lexNoLabel'], + ]; } } diff --git a/tests/Lexer/TokenTest.php b/tests/Lexer/TokenTest.php index 68d3b00..ba61e32 100644 --- a/tests/Lexer/TokenTest.php +++ b/tests/Lexer/TokenTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Lexer; diff --git a/tests/Lexer/TokensListTest.php b/tests/Lexer/TokensListTest.php index c1c4414..c963fdd 100644 --- a/tests/Lexer/TokensListTest.php +++ b/tests/Lexer/TokensListTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Lexer; @@ -18,9 +19,9 @@ class TokensListTest extends TestCase /** * Test setup. */ - public function setUp() + public function setUp(): void { - $this->tokens = array( + $this->tokens = [ new Token('SELECT', Token::TYPE_KEYWORD), new Token(' ', Token::TYPE_WHITESPACE), new Token('*', Token::TYPE_OPERATOR), @@ -28,8 +29,8 @@ class TokensListTest extends TestCase new Token('FROM', Token::TYPE_KEYWORD), new Token(' ', Token::TYPE_WHITESPACE), new Token('`test`', Token::TYPE_SYMBOL), - new Token(' ', Token::TYPE_WHITESPACE) - ); + new Token(' ', Token::TYPE_WHITESPACE), + ]; } public function testBuild() diff --git a/tests/Misc/BugsTest.php b/tests/Misc/BugsTest.php index d356b57..a467869 100644 --- a/tests/Misc/BugsTest.php +++ b/tests/Misc/BugsTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Misc; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class BugsTest extends TestCase { /** - * @dataProvider bugProvider - * * @param mixed $test + * + * @dataProvider bugProvider */ public function testBug($test) { @@ -18,15 +19,15 @@ class BugsTest extends TestCase public function bugProvider() { - return array( - array('bugs/gh9'), - array('bugs/gh14'), - array('bugs/gh16'), - array('bugs/pma11800'), - array('bugs/pma11836'), - array('bugs/pma11843'), - array('bugs/pma11867'), - array('bugs/pma11879') - ); + return [ + ['bugs/gh9'], + ['bugs/gh14'], + ['bugs/gh16'], + ['bugs/pma11800'], + ['bugs/pma11836'], + ['bugs/pma11843'], + ['bugs/pma11867'], + ['bugs/pma11879'], + ]; } } diff --git a/tests/Misc/ParameterTest.php b/tests/Misc/ParameterTest.php index f2d5280..cfabfb1 100644 --- a/tests/Misc/ParameterTest.php +++ b/tests/Misc/ParameterTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Misc; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class ParameterTest extends TestCase { /** - * @dataProvider parameterProvider - * * @param mixed $test + * + * @dataProvider parameterProvider */ public function testParameter($test) { @@ -18,8 +19,8 @@ class ParameterTest extends TestCase public function parameterProvider() { - return array( - array('misc/parseParameter') - ); + return [ + ['misc/parseParameter'], + ]; } } diff --git a/tests/Misc/UtfStringTest.php b/tests/Misc/UtfStringTest.php index 36f0298..965812f 100644 --- a/tests/Misc/UtfStringTest.php +++ b/tests/Misc/UtfStringTest.php @@ -1,9 +1,11 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Misc; use PhpMyAdmin\SqlParser\Tests\TestCase; use PhpMyAdmin\SqlParser\UtfString; +use Throwable; class UtfStringTest extends TestCase { @@ -36,22 +38,18 @@ class UtfStringTest extends TestCase $this->assertNull($str[static::TEST_PHRASE_LEN]); } - /** - * @expectedException \Exception - * @expectedExceptionMessage Not implemented. - */ public function testSet() { + $this->expectExceptionMessage('Not implemented.'); + $this->expectException(Throwable::class); $str = new UtfString(''); $str[0] = 'a'; } - /** - * @expectedException \Exception - * @expectedExceptionMessage Not implemented. - */ public function testUnset() { + $this->expectExceptionMessage('Not implemented.'); + $this->expectException(Throwable::class); $str = new UtfString(''); unset($str[0]); } @@ -86,11 +84,11 @@ class UtfStringTest extends TestCase /** * Test access to string. * - * @dataProvider utf8Strings - * * @param mixed $text * @param mixed $pos10 * @param mixed $pos20 + * + * @dataProvider utf8Strings */ public function testAccess($text, $pos10, $pos20) { @@ -102,27 +100,27 @@ class UtfStringTest extends TestCase public function utf8Strings() { - return array( - 'ascii' => array( + return [ + 'ascii' => [ 'abcdefghijklmnopqrstuvwxyz', 'k', 'u', - ), - 'unicode' => array( + ], + 'unicode' => [ 'áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň', 'ǐ', 'č', - ), - 'emoji' => array( + ], + 'emoji' => [ '😂😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯', '😂', '😋', - ), - 'iso' => array( + ], + 'iso' => [ "P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy", null, null, - ) - ); + ], + ]; } } diff --git a/tests/Parser/AlterStatementTest.php b/tests/Parser/AlterStatementTest.php index a8d6bdd..4e17677 100644 --- a/tests/Parser/AlterStatementTest.php +++ b/tests/Parser/AlterStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class AlterStatementTest extends TestCase { /** - * @dataProvider alterProvider - * * @param mixed $test + * + * @dataProvider alterProvider */ public function testAlter($test) { @@ -18,20 +19,20 @@ class AlterStatementTest extends TestCase public function alterProvider() { - return array( - array('parser/parseAlter'), - array('parser/parseAlter2'), - array('parser/parseAlter3'), - array('parser/parseAlter4'), - array('parser/parseAlter5'), - array('parser/parseAlter6'), - array('parser/parseAlter7'), - array('parser/parseAlter8'), - array('parser/parseAlter9'), - array('parser/parseAlter10'), - array('parser/parseAlterErr'), - array('parser/parseAlterErr2'), - array('parser/parseAlterErr3') - ); + return [ + ['parser/parseAlter'], + ['parser/parseAlter2'], + ['parser/parseAlter3'], + ['parser/parseAlter4'], + ['parser/parseAlter5'], + ['parser/parseAlter6'], + ['parser/parseAlter7'], + ['parser/parseAlter8'], + ['parser/parseAlter9'], + ['parser/parseAlter10'], + ['parser/parseAlterErr'], + ['parser/parseAlterErr2'], + ['parser/parseAlterErr3'], + ]; } } diff --git a/tests/Parser/CallStatementTest.php b/tests/Parser/CallStatementTest.php index a90d27a..3a71ce3 100644 --- a/tests/Parser/CallStatementTest.php +++ b/tests/Parser/CallStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class CallStatementTest extends TestCase { /** - * @dataProvider callProvider - * * @param mixed $test + * + * @dataProvider callProvider */ public function testCall($test) { @@ -18,10 +19,10 @@ class CallStatementTest extends TestCase public function callProvider() { - return array( - array('parser/parseCall'), - array('parser/parseCall2'), - array('parser/parseCall3') - ); + return [ + ['parser/parseCall'], + ['parser/parseCall2'], + ['parser/parseCall3'], + ]; } } diff --git a/tests/Parser/CreateStatementTest.php b/tests/Parser/CreateStatementTest.php index 3e328b1..eb69e01 100644 --- a/tests/Parser/CreateStatementTest.php +++ b/tests/Parser/CreateStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class CreateStatementTest extends TestCase { /** - * @dataProvider createProvider - * * @param mixed $test + * + * @dataProvider createProvider */ public function testCreate($test) { @@ -18,40 +19,40 @@ class CreateStatementTest extends TestCase public function createProvider() { - return array( - array('parser/parseCreateDatabase'), - array('parser/parseCreateDatabaseErr'), - array('parser/parseCreateFunction'), - array('parser/parseCreateFunctionErr1'), - array('parser/parseCreateFunctionErr2'), - array('parser/parseCreateFunctionErr3'), - array('parser/parseCreateProcedure'), - array('parser/parseCreateProcedure2'), - array('parser/parseCreateSchema'), - array('parser/parseCreateSchemaErr'), - array('parser/parseCreateTable'), - array('parser/parseCreateTable2'), - array('parser/parseCreateTable3'), - array('parser/parseCreateTable4'), - array('parser/parseCreateTable5'), - array('parser/parseCreateTable6'), - array('parser/parseCreateTable7'), - array('parser/parseCreateTableErr1'), - array('parser/parseCreateTableErr2'), - array('parser/parseCreateTableErr3'), - array('parser/parseCreateTableErr4'), - array('parser/parseCreateTableErr5'), - array('parser/parseCreateTableSelect'), - array('parser/parseCreateTableAsSelect'), - array('parser/parseCreateTableLike'), - array('parser/parseCreateTableSpatial'), - array('parser/parseCreateTableTimestampWithPrecision'), - array('parser/parseCreateTrigger'), - array('parser/parseCreateUser'), - array('parser/parseCreateView'), - array('parser/parseCreateView2'), - array('parser/parseCreateViewWithoutQuotes'), - array('parser/parseCreateViewWithQuotes'), - ); + return [ + ['parser/parseCreateDatabase'], + ['parser/parseCreateDatabaseErr'], + ['parser/parseCreateFunction'], + ['parser/parseCreateFunctionErr1'], + ['parser/parseCreateFunctionErr2'], + ['parser/parseCreateFunctionErr3'], + ['parser/parseCreateProcedure'], + ['parser/parseCreateProcedure2'], + ['parser/parseCreateSchema'], + ['parser/parseCreateSchemaErr'], + ['parser/parseCreateTable'], + ['parser/parseCreateTable2'], + ['parser/parseCreateTable3'], + ['parser/parseCreateTable4'], + ['parser/parseCreateTable5'], + ['parser/parseCreateTable6'], + ['parser/parseCreateTable7'], + ['parser/parseCreateTableErr1'], + ['parser/parseCreateTableErr2'], + ['parser/parseCreateTableErr3'], + ['parser/parseCreateTableErr4'], + ['parser/parseCreateTableErr5'], + ['parser/parseCreateTableSelect'], + ['parser/parseCreateTableAsSelect'], + ['parser/parseCreateTableLike'], + ['parser/parseCreateTableSpatial'], + ['parser/parseCreateTableTimestampWithPrecision'], + ['parser/parseCreateTrigger'], + ['parser/parseCreateUser'], + ['parser/parseCreateView'], + ['parser/parseCreateView2'], + ['parser/parseCreateViewWithoutQuotes'], + ['parser/parseCreateViewWithQuotes'], + ]; } } diff --git a/tests/Parser/DeleteStatementTest.php b/tests/Parser/DeleteStatementTest.php index 75f3b09..dc22c02 100644 --- a/tests/Parser/DeleteStatementTest.php +++ b/tests/Parser/DeleteStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class DeleteStatementTest extends TestCase { /** - * @dataProvider deleteProvider - * * @param mixed $test + * + * @dataProvider deleteProvider */ public function testDelete($test) { @@ -18,32 +19,32 @@ class DeleteStatementTest extends TestCase public function deleteProvider() { - return array( - array('parser/parseDelete'), - array('parser/parseDelete2'), - array('parser/parseDelete3'), - array('parser/parseDelete4'), - array('parser/parseDelete5'), - array('parser/parseDelete6'), - array('parser/parseDelete7'), - array('parser/parseDelete8'), - array('parser/parseDelete9'), - array('parser/parseDelete10'), - array('parser/parseDelete11'), - array('parser/parseDelete12'), - array('parser/parseDeleteErr1'), - array('parser/parseDeleteErr2'), - array('parser/parseDeleteErr3'), - array('parser/parseDeleteErr4'), - array('parser/parseDeleteErr5'), - array('parser/parseDeleteErr6'), - array('parser/parseDeleteErr7'), - array('parser/parseDeleteErr8'), - array('parser/parseDeleteErr9'), - array('parser/parseDeleteErr10'), - array('parser/parseDeleteErr11'), - array('parser/parseDeleteErr12'), - array('parser/parseDeleteJoin') - ); + return [ + ['parser/parseDelete'], + ['parser/parseDelete2'], + ['parser/parseDelete3'], + ['parser/parseDelete4'], + ['parser/parseDelete5'], + ['parser/parseDelete6'], + ['parser/parseDelete7'], + ['parser/parseDelete8'], + ['parser/parseDelete9'], + ['parser/parseDelete10'], + ['parser/parseDelete11'], + ['parser/parseDelete12'], + ['parser/parseDeleteErr1'], + ['parser/parseDeleteErr2'], + ['parser/parseDeleteErr3'], + ['parser/parseDeleteErr4'], + ['parser/parseDeleteErr5'], + ['parser/parseDeleteErr6'], + ['parser/parseDeleteErr7'], + ['parser/parseDeleteErr8'], + ['parser/parseDeleteErr9'], + ['parser/parseDeleteErr10'], + ['parser/parseDeleteErr11'], + ['parser/parseDeleteErr12'], + ['parser/parseDeleteJoin'], + ]; } } diff --git a/tests/Parser/DropStatementTest.php b/tests/Parser/DropStatementTest.php index ee71e16..0464367 100644 --- a/tests/Parser/DropStatementTest.php +++ b/tests/Parser/DropStatementTest.php @@ -18,9 +18,9 @@ class DropStatementTest extends TestCase public function dropProvider() { - return array( - array('parser/parseDrop'), - array('parser/parseDrop2'), - ); + return [ + ['parser/parseDrop'], + ['parser/parseDrop2'], + ]; } } diff --git a/tests/Parser/ExplainStatementTest.php b/tests/Parser/ExplainStatementTest.php index db66a0a..c00a99d 100644 --- a/tests/Parser/ExplainStatementTest.php +++ b/tests/Parser/ExplainStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class ExplainStatementTest extends TestCase { /** - * @dataProvider explainProvider - * * @param mixed $test + * + * @dataProvider explainProvider */ public function testExplain($test) { @@ -18,8 +19,8 @@ class ExplainStatementTest extends TestCase public function explainProvider() { - return array( - array('parser/parseExplain') - ); + return [ + ['parser/parseExplain'], + ]; } } diff --git a/tests/Parser/InsertStatementTest.php b/tests/Parser/InsertStatementTest.php index f0e4b5d..503cae9 100644 --- a/tests/Parser/InsertStatementTest.php +++ b/tests/Parser/InsertStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class InsertStatementTest extends TestCase { /** - * @dataProvider insertProvider - * * @param mixed $test + * + * @dataProvider insertProvider */ public function testInsert($test) { @@ -18,16 +19,16 @@ class InsertStatementTest extends TestCase public function insertProvider() { - return array( - array('parser/parseInsert'), - array('parser/parseInsertSelect'), - array('parser/parseInsertOnDuplicateKey'), - array('parser/parseInsertSetOnDuplicateKey'), - array('parser/parseInsertSelectOnDuplicateKey'), - array('parser/parseInsertOnDuplicateKeyErr'), - array('parser/parseInsertErr'), - array('parser/parseInsertErr2'), - array('parser/parseInsertIntoErr') - ); + return [ + ['parser/parseInsert'], + ['parser/parseInsertSelect'], + ['parser/parseInsertOnDuplicateKey'], + ['parser/parseInsertSetOnDuplicateKey'], + ['parser/parseInsertSelectOnDuplicateKey'], + ['parser/parseInsertOnDuplicateKeyErr'], + ['parser/parseInsertErr'], + ['parser/parseInsertErr2'], + ['parser/parseInsertIntoErr'], + ]; } } diff --git a/tests/Parser/LoadStatementTest.php b/tests/Parser/LoadStatementTest.php index 70d0a64..d19a012 100644 --- a/tests/Parser/LoadStatementTest.php +++ b/tests/Parser/LoadStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -16,9 +17,9 @@ class LoadStatementTest extends TestCase } /** - * @dataProvider loadProvider - * * @param mixed $test + * + * @dataProvider loadProvider */ public function testLoad($test) { @@ -27,19 +28,19 @@ class LoadStatementTest extends TestCase public function loadProvider() { - return array( - array('parser/parseLoad1'), - array('parser/parseLoad2'), - array('parser/parseLoad3'), - array('parser/parseLoad4'), - array('parser/parseLoad5'), - array('parser/parseLoad6'), - array('parser/parseLoadErr1'), - array('parser/parseLoadErr2'), - array('parser/parseLoadErr3'), - array('parser/parseLoadErr4'), - array('parser/parseLoadErr5'), - array('parser/parseLoadErr6') - ); + return [ + ['parser/parseLoad1'], + ['parser/parseLoad2'], + ['parser/parseLoad3'], + ['parser/parseLoad4'], + ['parser/parseLoad5'], + ['parser/parseLoad6'], + ['parser/parseLoadErr1'], + ['parser/parseLoadErr2'], + ['parser/parseLoadErr3'], + ['parser/parseLoadErr4'], + ['parser/parseLoadErr5'], + ['parser/parseLoadErr6'], + ]; } } diff --git a/tests/Parser/LockStatementTest.php b/tests/Parser/LockStatementTest.php index 5460254..d3c6e5d 100644 --- a/tests/Parser/LockStatementTest.php +++ b/tests/Parser/LockStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class LockStatementTest extends TestCase { /** - * @dataProvider lockProvider - * * @param mixed $test + * + * @dataProvider lockProvider */ public function testLock($test) { @@ -18,24 +19,24 @@ class LockStatementTest extends TestCase public function lockProvider() { - return array( - array('parser/parseLock1'), - array('parser/parseLock2'), - array('parser/parseLock3'), - array('parser/parseLock4'), - array('parser/parseLock5'), - array('parser/parseLockErr1'), - array('parser/parseLockErr2'), - array('parser/parseLockErr3'), - array('parser/parseLockErr4'), - array('parser/parseLockErr5'), - array('parser/parseLockErr6'), - array('parser/parseLockErr7'), - array('parser/parseLockErr8'), - array('parser/parseLockErr9'), - array('parser/parseLockErr10'), - array('parser/parseUnlock1'), - array('parser/parseUnlockErr1') - ); + return [ + ['parser/parseLock1'], + ['parser/parseLock2'], + ['parser/parseLock3'], + ['parser/parseLock4'], + ['parser/parseLock5'], + ['parser/parseLockErr1'], + ['parser/parseLockErr2'], + ['parser/parseLockErr3'], + ['parser/parseLockErr4'], + ['parser/parseLockErr5'], + ['parser/parseLockErr6'], + ['parser/parseLockErr7'], + ['parser/parseLockErr8'], + ['parser/parseLockErr9'], + ['parser/parseLockErr10'], + ['parser/parseUnlock1'], + ['parser/parseUnlockErr1'], + ]; } } diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php index 57c4aae..cba4868 100644 --- a/tests/Parser/ParserTest.php +++ b/tests/Parser/ParserTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -11,9 +12,9 @@ use PhpMyAdmin\SqlParser\TokensList; class ParserTest extends TestCase { /** - * @dataProvider parseProvider - * * @param mixed $test + * + * @dataProvider parseProvider */ public function testParse($test) { @@ -22,11 +23,11 @@ class ParserTest extends TestCase public function parseProvider() { - return array( - array('parser/parse'), - array('parser/parse2'), - array('parser/parseDelimiter') - ); + return [ + ['parser/parse'], + ['parser/parse2'], + ['parser/parseDelimiter'], + ]; } public function testUnrecognizedStatement() @@ -60,20 +61,18 @@ class ParserTest extends TestCase $this->assertEquals( $parser->errors, - array( + [ new ParserException('error #1', new Token('foo'), 1), new ParserException('error #2', new Token('bar'), 2), - ) + ] ); } - /** - * @expectedException \PhpMyAdmin\SqlParser\Exceptions\ParserException - * @expectedExceptionMessage strict error - * @expectedExceptionCode 3 - */ public function testErrorStrict() { + $this->expectExceptionCode(3); + $this->expectExceptionMessage('strict error'); + $this->expectException(ParserException::class); $parser = new Parser(new TokensList()); $parser->strict = true; diff --git a/tests/Parser/PurgeStatementTest.php b/tests/Parser/PurgeStatementTest.php index 364c5a3..4e66e52 100644 --- a/tests/Parser/PurgeStatementTest.php +++ b/tests/Parser/PurgeStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class PurgeStatementTest extends TestCase { /** - * @dataProvider purgeProvider - * * @param mixed $test + * + * @dataProvider purgeProvider */ public function testPurge($test) { @@ -18,14 +19,14 @@ class PurgeStatementTest extends TestCase public function purgeProvider() { - return array( - array('parser/parsePurge'), - array('parser/parsePurge2'), - array('parser/parsePurge3'), - array('parser/parsePurge4'), - array('parser/parsePurgeErr'), - array('parser/parsePurgeErr2'), - array('parser/parsePurgeErr3') - ); + return [ + ['parser/parsePurge'], + ['parser/parsePurge2'], + ['parser/parsePurge3'], + ['parser/parsePurge4'], + ['parser/parsePurgeErr'], + ['parser/parsePurgeErr2'], + ['parser/parsePurgeErr3'], + ]; } } diff --git a/tests/Parser/RenameStatementTest.php b/tests/Parser/RenameStatementTest.php index bb13c3c..bfbe34f 100644 --- a/tests/Parser/RenameStatementTest.php +++ b/tests/Parser/RenameStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class RenameStatementTest extends TestCase { /** - * @dataProvider renameProvider - * * @param mixed $test + * + * @dataProvider renameProvider */ public function testRename($test) { @@ -18,14 +19,14 @@ class RenameStatementTest extends TestCase public function renameProvider() { - return array( - array('parser/parseRename'), - array('parser/parseRename2'), - array('parser/parseRenameErr1'), - array('parser/parseRenameErr2'), - array('parser/parseRenameErr3'), - array('parser/parseRenameErr4'), - array('parser/parseRenameErr5') - ); + return [ + ['parser/parseRename'], + ['parser/parseRename2'], + ['parser/parseRenameErr1'], + ['parser/parseRenameErr2'], + ['parser/parseRenameErr3'], + ['parser/parseRenameErr4'], + ['parser/parseRenameErr5'], + ]; } } diff --git a/tests/Parser/ReplaceStatementTest.php b/tests/Parser/ReplaceStatementTest.php index edac536..4698c4b 100644 --- a/tests/Parser/ReplaceStatementTest.php +++ b/tests/Parser/ReplaceStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class ReplaceStatementTest extends TestCase { /** - * @dataProvider replaceProvider - * * @param mixed $test + * + * @dataProvider replaceProvider */ public function testReplace($test) { @@ -18,16 +19,16 @@ class ReplaceStatementTest extends TestCase public function replaceProvider() { - return array( - array('parser/parseReplace'), - array('parser/parseReplace2'), - array('parser/parseReplaceValues'), - array('parser/parseReplaceSet'), - array('parser/parseReplaceSelect'), - array('parser/parseReplaceErr'), - array('parser/parseReplaceErr2'), - array('parser/parseReplaceErr3'), - array('parser/parseReplaceIntoErr') - ); + return [ + ['parser/parseReplace'], + ['parser/parseReplace2'], + ['parser/parseReplaceValues'], + ['parser/parseReplaceSet'], + ['parser/parseReplaceSelect'], + ['parser/parseReplaceErr'], + ['parser/parseReplaceErr2'], + ['parser/parseReplaceErr3'], + ['parser/parseReplaceIntoErr'], + ]; } } diff --git a/tests/Parser/RestoreStatementTest.php b/tests/Parser/RestoreStatementTest.php index 7fa9a5d..783c68e 100644 --- a/tests/Parser/RestoreStatementTest.php +++ b/tests/Parser/RestoreStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class RestoreStatementTest extends TestCase { /** - * @dataProvider restoreProvider - * * @param mixed $test + * + * @dataProvider restoreProvider */ public function testRestore($test) { @@ -18,8 +19,8 @@ class RestoreStatementTest extends TestCase public function restoreProvider() { - return array( - array('parser/parseRestore') - ); + return [ + ['parser/parseRestore'], + ]; } } diff --git a/tests/Parser/SelectStatementTest.php b/tests/Parser/SelectStatementTest.php index f4e1e90..3649412 100644 --- a/tests/Parser/SelectStatementTest.php +++ b/tests/Parser/SelectStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -16,9 +17,9 @@ class SelectStatementTest extends TestCase } /** - * @dataProvider selectProvider - * * @param mixed $test + * + * @dataProvider selectProvider */ public function testSelect($test) { @@ -27,65 +28,65 @@ class SelectStatementTest extends TestCase public function selectProvider() { - return array( - array('parser/parseSelect2'), - array('parser/parseSelect3'), - array('parser/parseSelect4'), - array('parser/parseSelect5'), - array('parser/parseSelect6'), - array('parser/parseSelect7'), - array('parser/parseSelect8'), - array('parser/parseSelect9'), - array('parser/parseSelect10'), - array('parser/parseSelect11'), - array('parser/parseSelectErr1'), - array('parser/parseSelectErr2'), - array('parser/parseSelectNested'), - array('parser/parseSelectCase1'), - array('parser/parseSelectCase2'), - array('parser/parseSelectCase3'), - array('parser/parseSelectCase4'), - array('parser/parseSelectCase5'), - array('parser/parseSelectCaseErr1'), - array('parser/parseSelectCaseErr2'), - array('parser/parseSelectCaseErr3'), - array('parser/parseSelectCaseErr4'), - array('parser/parseSelectCaseErr5'), - array('parser/parseSelectCaseAlias1'), - array('parser/parseSelectCaseAlias2'), - array('parser/parseSelectCaseAlias3'), - array('parser/parseSelectCaseAlias4'), - array('parser/parseSelectCaseAlias5'), - array('parser/parseSelectCaseAlias6'), - array('parser/parseSelectCaseAliasErr1'), - array('parser/parseSelectCaseAliasErr2'), - array('parser/parseSelectCaseAliasErr3'), - array('parser/parseSelectCaseAliasErr4'), - array('parser/parseSelectIntoOptions1'), - array('parser/parseSelectIntoOptions2'), - array('parser/parseSelectIntoOptions3'), - array('parser/parseSelectJoinCross'), - array('parser/parseSelectJoinNatural'), - array('parser/parseSelectJoinNaturalLeft'), - array('parser/parseSelectJoinNaturalRight'), - array('parser/parseSelectJoinNaturalLeftOuter'), - array('parser/parseSelectJoinNaturalRightOuter'), - array('parser/parseSelectJoinMultiple'), - array('parser/parseSelectJoinMultiple2'), - array('parser/parseSelectWrongOrder'), - array('parser/parseSelectWrongOrder2'), - array('parser/parseSelectEndOptions1'), - array('parser/parseSelectEndOptions2'), - array('parser/parseSelectEndOptionsErr'), - array('parser/parseSelectUnion'), - array('parser/parseSelectUnion2'), - array('parser/parseSelectIndexHint1'), - array('parser/parseSelectIndexHint2'), - array('parser/parseSelectIndexHintErr1'), - array('parser/parseSelectIndexHintErr2'), - array('parser/parseSelectIndexHintErr3'), - array('parser/parseSelectIndexHintErr4'), - array('parser/parseSelectWithParenthesis') - ); + return [ + ['parser/parseSelect2'], + ['parser/parseSelect3'], + ['parser/parseSelect4'], + ['parser/parseSelect5'], + ['parser/parseSelect6'], + ['parser/parseSelect7'], + ['parser/parseSelect8'], + ['parser/parseSelect9'], + ['parser/parseSelect10'], + ['parser/parseSelect11'], + ['parser/parseSelectErr1'], + ['parser/parseSelectErr2'], + ['parser/parseSelectNested'], + ['parser/parseSelectCase1'], + ['parser/parseSelectCase2'], + ['parser/parseSelectCase3'], + ['parser/parseSelectCase4'], + ['parser/parseSelectCase5'], + ['parser/parseSelectCaseErr1'], + ['parser/parseSelectCaseErr2'], + ['parser/parseSelectCaseErr3'], + ['parser/parseSelectCaseErr4'], + ['parser/parseSelectCaseErr5'], + ['parser/parseSelectCaseAlias1'], + ['parser/parseSelectCaseAlias2'], + ['parser/parseSelectCaseAlias3'], + ['parser/parseSelectCaseAlias4'], + ['parser/parseSelectCaseAlias5'], + ['parser/parseSelectCaseAlias6'], + ['parser/parseSelectCaseAliasErr1'], + ['parser/parseSelectCaseAliasErr2'], + ['parser/parseSelectCaseAliasErr3'], + ['parser/parseSelectCaseAliasErr4'], + ['parser/parseSelectIntoOptions1'], + ['parser/parseSelectIntoOptions2'], + ['parser/parseSelectIntoOptions3'], + ['parser/parseSelectJoinCross'], + ['parser/parseSelectJoinNatural'], + ['parser/parseSelectJoinNaturalLeft'], + ['parser/parseSelectJoinNaturalRight'], + ['parser/parseSelectJoinNaturalLeftOuter'], + ['parser/parseSelectJoinNaturalRightOuter'], + ['parser/parseSelectJoinMultiple'], + ['parser/parseSelectJoinMultiple2'], + ['parser/parseSelectWrongOrder'], + ['parser/parseSelectWrongOrder2'], + ['parser/parseSelectEndOptions1'], + ['parser/parseSelectEndOptions2'], + ['parser/parseSelectEndOptionsErr'], + ['parser/parseSelectUnion'], + ['parser/parseSelectUnion2'], + ['parser/parseSelectIndexHint1'], + ['parser/parseSelectIndexHint2'], + ['parser/parseSelectIndexHintErr1'], + ['parser/parseSelectIndexHintErr2'], + ['parser/parseSelectIndexHintErr3'], + ['parser/parseSelectIndexHintErr4'], + ['parser/parseSelectWithParenthesis'], + ]; } } diff --git a/tests/Parser/SetStatementTest.php b/tests/Parser/SetStatementTest.php index 9d31659..9c8af23 100644 --- a/tests/Parser/SetStatementTest.php +++ b/tests/Parser/SetStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class SetStatementTest extends TestCase { /** - * @dataProvider setProvider - * * @param mixed $test + * + * @dataProvider setProvider */ public function testSet($test) { @@ -18,14 +19,14 @@ class SetStatementTest extends TestCase public function setProvider() { - return array( - array('parser/parseSetCharset'), - array('parser/parseSetCharsetError'), - array('parser/parseSetCharacterSet'), - array('parser/parseSetCharacterSetError'), - array('parser/parseSetNames'), - array('parser/parseSetNamesError'), - array('parser/parseSetError1') - ); + return [ + ['parser/parseSetCharset'], + ['parser/parseSetCharsetError'], + ['parser/parseSetCharacterSet'], + ['parser/parseSetCharacterSetError'], + ['parser/parseSetNames'], + ['parser/parseSetNamesError'], + ['parser/parseSetError1'], + ]; } } diff --git a/tests/Parser/TransactionStatementTest.php b/tests/Parser/TransactionStatementTest.php index 599015f..b4b8fca 100644 --- a/tests/Parser/TransactionStatementTest.php +++ b/tests/Parser/TransactionStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class TransactionStatementTest extends TestCase { /** - * @dataProvider transactionProvider - * * @param mixed $test + * + * @dataProvider transactionProvider */ public function testTransaction($test) { @@ -18,11 +19,11 @@ class TransactionStatementTest extends TestCase public function transactionProvider() { - return array( - array('parser/parseTransaction'), - array('parser/parseTransaction2'), - array('parser/parseTransaction3'), - array('parser/parseTransactionErr1') - ); + return [ + ['parser/parseTransaction'], + ['parser/parseTransaction2'], + ['parser/parseTransaction3'], + ['parser/parseTransactionErr1'], + ]; } } diff --git a/tests/Parser/UpdateStatementTest.php b/tests/Parser/UpdateStatementTest.php index 210e1ab..2ebb478 100644 --- a/tests/Parser/UpdateStatementTest.php +++ b/tests/Parser/UpdateStatementTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Parser; @@ -7,9 +8,9 @@ use PhpMyAdmin\SqlParser\Tests\TestCase; class UpdateStatementTest extends TestCase { /** - * @dataProvider updateProvider - * * @param mixed $test + * + * @dataProvider updateProvider */ public function testUpdate($test) { @@ -18,11 +19,11 @@ class UpdateStatementTest extends TestCase public function updateProvider() { - return array( - array('parser/parseUpdate'), - array('parser/parseUpdate2'), - array('parser/parseUpdate3'), - array('parser/parseUpdateErr') - ); + return [ + ['parser/parseUpdate'], + ['parser/parseUpdate2'], + ['parser/parseUpdate3'], + ['parser/parseUpdateErr'], + ]; } } diff --git a/tests/TestCase.php b/tests/TestCase.php index fb6af8d..d464f24 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1,11 +1,13 @@ <?php - /** * Bootstrap for tests. */ +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests; +use PhpMyAdmin\SqlParser\Exceptions\LexerException; +use PhpMyAdmin\SqlParser\Exceptions\ParserException; use PhpMyAdmin\SqlParser\Lexer; use PhpMyAdmin\SqlParser\Parser; use PhpMyAdmin\SqlParser\TokensList; @@ -15,10 +17,6 @@ $GLOBALS['lang'] = 'en'; /** * Implements useful methods for testing. - * - * @category Tests - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ abstract class TestCase extends BaseTestCase { @@ -45,20 +43,21 @@ abstract class TestCase extends BaseTestCase */ public function getErrorsAsArray($obj) { - $ret = array(); + $ret = []; + /** @var LexerException|ParserException $err */ foreach ($obj->errors as $err) { $ret[] = $obj instanceof Lexer - ? array( + ? [ $err->getMessage(), $err->ch, $err->pos, $err->getCode(), - ) - : array( + ] + : [ $err->getMessage(), $err->token, - $err->getCode() - ); + $err->getCode(), + ]; } return $ret; @@ -101,14 +100,14 @@ abstract class TestCase extends BaseTestCase // Lexer. $lexer = new Lexer($data['query']); $lexerErrors = $this->getErrorsAsArray($lexer); - $lexer->errors = array(); + $lexer->errors = []; // Parser. $parser = empty($data['parser']) ? null : new Parser($lexer->list); - $parserErrors = array(); + $parserErrors = []; if ($parser !== null) { $parserErrors = $this->getErrorsAsArray($parser); - $parser->errors = array(); + $parser->errors = []; } // Testing objects. diff --git a/tests/Utils/BufferedQueryTest.php b/tests/Utils/BufferedQueryTest.php index 164c31e..2718126 100644 --- a/tests/Utils/BufferedQueryTest.php +++ b/tests/Utils/BufferedQueryTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; @@ -8,10 +9,10 @@ use PhpMyAdmin\SqlParser\Utils\BufferedQuery; class BufferedQueryTest extends TestCase { /** - * @dataProvider extractProvider - * * @param mixed $query * @param mixed $chunkSize + * + * @dataProvider extractProvider */ public function testExtract( $query, @@ -27,7 +28,7 @@ class BufferedQueryTest extends TestCase * * @var array */ - $statements = array(); + $statements = []; /** * The `BufferedQuery` instance used for extraction. @@ -99,21 +100,21 @@ class BufferedQueryTest extends TestCase '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;' . "\n" . '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */'; - return array( - array( + return [ + [ "SELECT '\'';\nSELECT '\'';", 8, - array( + [ 'parse_delimiter' => true, 'add_delimiter' => true, - ), - array( + ], + [ "SELECT '\'';", "SELECT '\'';", - ), - ), + ], + ], - array( + [ "CREATE TABLE `test` (\n" . " `txt` varchar(10)\n" . ");\n" . @@ -121,58 +122,58 @@ class BufferedQueryTest extends TestCase "INSERT INTO `test` (`txt`) VALUES('\\\\');\n" . "INSERT INTO `test` (`txt`) VALUES('xyz');\n", 8, - array( + [ 'parse_delimiter' => true, 'add_delimiter' => true, - ), - array( + ], + [ "CREATE TABLE `test` (\n" . " `txt` varchar(10)\n" . ');', "INSERT INTO `test` (`txt`) VALUES('abc');", "INSERT INTO `test` (`txt`) VALUES('\\\\');", "INSERT INTO `test` (`txt`) VALUES('xyz');", - ), - ), + ], + ], - array( + [ 'SELECT """""""";' . 'SELECT """\\\\"""', 8, - array( + [ 'parse_delimiter' => true, 'add_delimiter' => true, - ), - array( + ], + [ 'SELECT """""""";', 'SELECT """\\\\"""', - ), - ), + ], + ], - array( + [ 'DELIMITER A_VERY_LONG_DEL' . "\n" . 'SELECT 1 A_VERY_LONG_DEL' . "\n" . 'DELIMITER ;', 3, - array( + [ 'parse_delimiter' => true, 'add_delimiter' => true, - ), - array( + ], + [ 'DELIMITER A_VERY_LONG_DEL', 'SELECT 1 A_VERY_LONG_DEL', 'DELIMITER ;', - ), - ), + ], + ], - array( + [ $query, 32, - array( + [ 'parse_delimiter' => false, 'add_delimiter' => false, - ), - array( + ], + [ '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */', '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */', @@ -216,17 +217,17 @@ class BufferedQueryTest extends TestCase '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */', '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */', - ), - ), + ], + ], - array( + [ $query, 32, - array( + [ 'parse_delimiter' => true, 'add_delimiter' => false, - ), - array( + ], + [ '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */', '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */', @@ -274,17 +275,17 @@ class BufferedQueryTest extends TestCase '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */', '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */', - ), - ), + ], + ], - array( + [ $query, 64, - array( + [ 'parse_delimiter' => false, 'add_delimiter' => true, - ), - array( + ], + [ '/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;', '/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;', @@ -328,8 +329,8 @@ class BufferedQueryTest extends TestCase '/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;', '/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */', - ), - ) - ); + ], + ], + ]; } } diff --git a/tests/Utils/CLITest.php b/tests/Utils/CLITest.php index 4caa70d..2f7102f 100644 --- a/tests/Utils/CLITest.php +++ b/tests/Utils/CLITest.php @@ -1,14 +1,16 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; use PhpMyAdmin\SqlParser\Tests\TestCase; +use PhpMyAdmin\SqlParser\Utils\CLI; class CLITest extends TestCase { private function getCLI($getopt) { - $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(array('getopt'))->getMock(); + $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(['getopt'])->getMock(); $cli->method('getopt')->willReturn($getopt); return $cli; @@ -16,7 +18,7 @@ class CLITest extends TestCase private function getCLIStdIn($input, $getopt) { - $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(array('getopt', 'readStdin'))->getMock(); + $cli = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\CLI')->setMethods(['getopt', 'readStdin'])->getMock(); $cli->method('getopt')->willReturn($getopt); $cli->method('readStdin')->willReturn($input); return $cli; @@ -29,19 +31,19 @@ class CLITest extends TestCase */ public function testGetopt() { - $cli = new \PhpMyAdmin\SqlParser\Utils\CLI(); + $cli = new CLI(); $this->assertEquals( - $cli->getopt('', array()), - array() + $cli->getopt('', []), + [] ); } /** - * @dataProvider highlightParams - * * @param mixed $getopt * @param mixed $output * @param mixed $result + * + * @dataProvider highlightParams */ public function testRunHighlight($getopt, $output, $result) { @@ -52,61 +54,61 @@ class CLITest extends TestCase public function highlightParams() { - return array( - array( - array('q' => 'SELECT 1'), + return [ + [ + ['q' => 'SELECT 1'], "\x1b[35mSELECT\n \x1b[92m1\x1b[0m\n", - 0 - ), - array( - array('query' => 'SELECT 1'), + 0, + ], + [ + ['query' => 'SELECT 1'], "\x1b[35mSELECT\n \x1b[92m1\x1b[0m\n", - 0 - ), - array( - array( + 0, + ], + [ + [ 'q' => 'SELECT /* comment */ 1 /* other */', 'f' => 'text', - ), + ], "SELECT\n /* comment */ 1 /* other */\n", - 0 - ), - array( - array( + 0, + ], + [ + [ 'q' => 'SELECT 1', 'f' => 'foo', - ), + ], "ERROR: Invalid value for format!\n", - 1 - ), - array( - array( + 1, + ], + [ + [ 'q' => 'SELECT 1', 'f' => 'html', - ), - '<span class="sql-reserved">SELECT</span>' . '<br/>' . + ], + '<span class="sql-reserved">SELECT</span><br/>' . ' <span class="sql-number">1</span>' . "\n", - 0 - ), - array( - array('h' => true), + 0, + ], + [ + ['h' => true], 'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n" . ' cat file.sql | highlight-query' . "\n", - 0 - ), - array( - array(), + 0, + ], + [ + [], 'ERROR: Missing parameters!' . "\n" . 'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n" . ' cat file.sql | highlight-query' . "\n", 1, - ), - array( + ], + [ false, '', - 1 - ) - ); + 1, + ], + ]; } @@ -127,69 +129,69 @@ class CLITest extends TestCase public function highlightParamsStdIn() { - return array( - array( + return [ + [ 'SELECT 1', - array(), + [], "\x1b[35mSELECT\n \x1b[92m1\x1b[0m\n", - 0 - ), - array( + 0, + ], + [ 'SELECT /* comment */ 1 /* other */', - array( + [ 'f' => 'text', - ), + ], "SELECT\n /* comment */ 1 /* other */\n", - 0 - ), - array( + 0, + ], + [ 'SELECT 1', - array( + [ 'f' => 'foo', - ), + ], "ERROR: Invalid value for format!\n", - 1 - ), - array( + 1, + ], + [ 'SELECT 1', - array( + [ 'f' => 'html', - ), + ], '<span class="sql-reserved">SELECT</span>' . '<br/>' . ' <span class="sql-number">1</span>' . "\n", - 0 - ), - array( + 0, + ], + [ '', - array('h' => true), + ['h' => true], 'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n" . ' cat file.sql | highlight-query' . "\n", - 0 - ), - array( + 0, + ], + [ '', - array(), + [], 'ERROR: Missing parameters!' . "\n" . 'Usage: highlight-query --query SQL [--format html|cli|text]' . "\n" . ' cat file.sql | highlight-query' . "\n", 1, - ), - array( + ], + [ '', false, '', - 1 - ) - ); + 1, + ], + ]; } /** - * @dataProvider lintParamsStdIn - * * @param mixed $input * @param mixed $getopt * @param mixed $output * @param mixed $result + * + * @dataProvider lintParamsStdIn */ public function testRunLintFromStdIn($input, $getopt, $output, $result) { @@ -200,59 +202,59 @@ class CLITest extends TestCase public function lintParamsStdIn() { - return array( - array( + return [ + [ 'SELECT 1', - array(), + [], '', 0, - ), - array( + ], + [ 'SELECT SELECT', - array(), + [], '#1: An expression was expected. (near "SELECT" at position 7)' . "\n" . '#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" . '#3: An expression was expected. (near "" at position 0)' . "\n", 10, - ), - array( + ], + [ 'SELECT SELECT', - array('c' => 'MySql80000'), + ['c' => 'MySql80000'], '#1: An expression was expected. (near "SELECT" at position 7)' . "\n" . '#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" . '#3: An expression was expected. (near "" at position 0)' . "\n", 10, - ), - array( + ], + [ '', - array(), + [], 'ERROR: Missing parameters!' . "\n" . 'Usage: lint-query --query SQL' . "\n" . ' cat file.sql | lint-query' . "\n", 1, - ), - array( + ], + [ '', - array('h' => true), + ['h' => true], 'Usage: lint-query --query SQL' . "\n" . ' cat file.sql | lint-query' . "\n", 0, - ), - array( + ], + [ '', false, '', 1, - ) - ); + ], + ]; } /** - * @dataProvider lintParams - * * @param mixed $getopt * @param mixed $output * @param mixed $result + * + * @dataProvider lintParams */ public function testRunLint($getopt, $output, $result) { @@ -263,58 +265,61 @@ class CLITest extends TestCase public function lintParams() { - return array( - array( - array('q' => 'SELECT 1'), + return [ + [ + ['q' => 'SELECT 1'], '', 0, - ), - array( - array('query' => 'SELECT 1'), + ], + [ + ['query' => 'SELECT 1'], '', 0, - ), - array( - array('q' => 'SELECT SELECT'), + ], + [ + ['q' => 'SELECT SELECT'], '#1: An expression was expected. (near "SELECT" at position 7)' . "\n" . '#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" . '#3: An expression was expected. (near "" at position 0)' . "\n", 10, - ), - array( - array('q' => 'SELECT SELECT', 'c' => 'MySql80000'), + ], + [ + [ + 'q' => 'SELECT SELECT', + 'c' => 'MySql80000', + ], '#1: An expression was expected. (near "SELECT" at position 7)' . "\n" . '#2: This type of clause was previously parsed. (near "SELECT" at position 7)' . "\n" . '#3: An expression was expected. (near "" at position 0)' . "\n", 10, - ), - array( - array('h' => true), + ], + [ + ['h' => true], 'Usage: lint-query --query SQL' . "\n" . ' cat file.sql | lint-query' . "\n", 0, - ), - array( - array(), + ], + [ + [], 'ERROR: Missing parameters!' . "\n" . 'Usage: lint-query --query SQL' . "\n" . ' cat file.sql | lint-query' . "\n", 1, - ), - array( + ], + [ false, '', 1, - ) - ); + ], + ]; } /** - * @dataProvider tokenizeParams - * * @param mixed $getopt * @param mixed $output * @param mixed $result + * + * @dataProvider tokenizeParams */ public function testRunTokenize($getopt, $output, $result) { @@ -325,52 +330,50 @@ class CLITest extends TestCase public function tokenizeParams() { - $result = ( - "[TOKEN 0]\nType = 1\nFlags = 3\nValue = 'SELECT'\nToken = 'SELECT'\n\n" + $result = "[TOKEN 0]\nType = 1\nFlags = 3\nValue = 'SELECT'\nToken = 'SELECT'\n\n" . "[TOKEN 1]\nType = 3\nFlags = 0\nValue = ' '\nToken = ' '\n\n" . "[TOKEN 2]\nType = 6\nFlags = 0\nValue = 1\nToken = '1'\n\n" - . "[TOKEN 3]\nType = 9\nFlags = 0\nValue = NULL\nToken = NULL\n\n" - ); + . "[TOKEN 3]\nType = 9\nFlags = 0\nValue = NULL\nToken = NULL\n\n"; - return array( - array( - array('q' => 'SELECT 1'), + return [ + [ + ['q' => 'SELECT 1'], $result, 0, - ), - array( - array('query' => 'SELECT 1'), + ], + [ + ['query' => 'SELECT 1'], $result, 0, - ), - array( - array('h' => true), + ], + [ + ['h' => true], 'Usage: tokenize-query --query SQL' . "\n" . ' cat file.sql | tokenize-query' . "\n", 0, - ), - array( - array(), + ], + [ + [], 'ERROR: Missing parameters!' . "\n" . 'Usage: tokenize-query --query SQL' . "\n" . ' cat file.sql | tokenize-query' . "\n", 1, - ), - array( + ], + [ false, '', 1, - ) - ); + ], + ]; } /** - * @dataProvider tokenizeParamsStdIn - * * @param mixed $input * @param mixed $getopt * @param mixed $output * @param mixed $result + * + * @dataProvider tokenizeParamsStdIn */ public function testRunTokenizeStdIn($input, $getopt, $output, $result) { @@ -388,64 +391,78 @@ class CLITest extends TestCase . "[TOKEN 3]\nType = 9\nFlags = 0\nValue = NULL\nToken = NULL\n\n" ); - return array( - array( + return [ + [ 'SELECT 1', - array(), + [], $result, 0, - ), - array( + ], + [ '', - array('h' => true), + ['h' => true], 'Usage: tokenize-query --query SQL' . "\n" . ' cat file.sql | tokenize-query' . "\n", 0, - ), - array( + ], + [ '', - array(), + [], 'ERROR: Missing parameters!' . "\n" . 'Usage: tokenize-query --query SQL' . "\n" . ' cat file.sql | tokenize-query' . "\n", 1, - ), - array( + ], + [ '', false, '', 1, - ) - ); + ], + ]; } /** - * @dataProvider stdinParams - * * @param string $cmd - * @param int $result + * @param int $result + * + * @dataProvider stdinParams */ public function testStdinPipe($cmd, $result) { - exec ($cmd, $out, $ret); + exec($cmd, $out, $ret); $this->assertSame($result, $ret); } public function stdinParams() { - if (defined('PHP_BINARY')) { - $binPath = PHP_BINARY . ' ' . realpath(dirname(__DIR__) . '/../') . '/bin/'; - } else { - $binPath = 'php' . ' ' . realpath(dirname(__DIR__) . '/../') . '/bin/'; - } + $binPath = PHP_BINARY . ' ' . dirname(__DIR__, 2) . '/bin/'; - return array( - array('echo "SELECT 1" | '. $binPath .'highlight-query', 0), - array('echo "invalid query" | '. $binPath .'highlight-query', 0), - array('echo "SELECT 1" | '. $binPath .'lint-query', 0), - array('echo "invalid query" | '. $binPath .'lint-query', 10), - array('echo "SELECT 1" | '. $binPath .'tokenize-query', 0), - array('echo "invalid query" | '. $binPath .'tokenize-query', 0) - ); + return [ + [ + 'echo "SELECT 1" | ' . $binPath . 'highlight-query', + 0, + ], + [ + 'echo "invalid query" | ' . $binPath . 'highlight-query', + 0, + ], + [ + 'echo "SELECT 1" | ' . $binPath . 'lint-query', + 0, + ], + [ + 'echo "invalid query" | ' . $binPath . 'lint-query', + 10, + ], + [ + 'echo "SELECT 1" | ' . $binPath . 'tokenize-query', + 0, + ], + [ + 'echo "invalid query" | ' . $binPath . 'tokenize-query', + 0, + ], + ]; } } diff --git a/tests/Utils/ErrorTest.php b/tests/Utils/ErrorTest.php index be8e17d..eec1130 100644 --- a/tests/Utils/ErrorTest.php +++ b/tests/Utils/ErrorTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; @@ -14,33 +15,36 @@ class ErrorTest extends TestCase $lexer = new Lexer('SELECT * FROM db..tbl $'); $parser = new Parser($lexer->list); $this->assertEquals( - array( - array( + [ + [ 'Unexpected character.', 0, '$', 22, - ), - array( + ], + [ 'Unexpected dot.', 0, '.', 17, - ), - ), - Error::get(array($lexer, $parser)) + ], + ], + Error::get([$lexer, $parser]) ); } public function testFormat() { $this->assertEquals( - array('#1: error msg (near "token" at position 100)'), - Error::format(array(array('error msg', 42, 'token', 100))) + ['#1: error msg (near "token" at position 100)'], + Error::format([['error msg', 42, 'token', 100]]) ); $this->assertEquals( - array('#1: error msg (near "token" at position 100)', '#2: error msg (near "token" at position 200)'), - Error::format(array(array('error msg', 42, 'token', 100), array('error msg', 42, 'token', 200))) + [ + '#1: error msg (near "token" at position 100)', + '#2: error msg (near "token" at position 200)', + ], + Error::format([['error msg', 42, 'token', 100], ['error msg', 42, 'token', 200]]) ); } } diff --git a/tests/Utils/FormatterTest.php b/tests/Utils/FormatterTest.php index 3551dc6..9f5fbb5 100644 --- a/tests/Utils/FormatterTest.php +++ b/tests/Utils/FormatterTest.php @@ -1,276 +1,278 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; use PhpMyAdmin\SqlParser\Tests\TestCase; use PhpMyAdmin\SqlParser\Utils\Formatter; +use ReflectionMethod; class FormatterTest extends TestCase { /** - * @dataProvider mergeFormats - * * @param mixed $default * @param mixed $overriding * @param mixed $expected + * + * @dataProvider mergeFormats */ public function testMergeFormats($default, $overriding, $expected) { $formatter = $this->getMockBuilder('PhpMyAdmin\SqlParser\Utils\Formatter') ->disableOriginalConstructor() - ->setMethods(array('getDefaultOptions', 'getDefaultFormats')) + ->setMethods(['getDefaultOptions', 'getDefaultFormats']) ->getMock(); $formatter->expects($this->once()) ->method('getDefaultOptions') - ->willReturn(array( + ->willReturn([ 'type' => 'text', 'line_ending' => null, 'indentation' => null, 'clause_newline' => null, - 'parts_newline' => null - )); + 'parts_newline' => null, + ]); $formatter->expects($this->once()) ->method('getDefaultFormats') ->willReturn($default); - $expectedOptions = array( + $expectedOptions = [ 'type' => 'test-type', 'line_ending' => '<br>', 'indentation' => ' ', 'clause_newline' => null, 'parts_newline' => 0, - 'formats' => $expected - ); + 'formats' => $expected, + ]; - $overridingOptions = array( + $overridingOptions = [ 'type' => 'test-type', 'line_ending' => '<br>', - 'formats' => $overriding - ); + 'formats' => $overriding, + ]; - $reflectionMethod = new \ReflectionMethod($formatter, 'getMergedOptions'); + $reflectionMethod = new ReflectionMethod($formatter, 'getMergedOptions'); $reflectionMethod->setAccessible(true); $this->assertEquals($expectedOptions, $reflectionMethod->invoke($formatter, $overridingOptions)); } public function mergeFormats() { - // array($default[], $overriding[], $expected[]) - return array( - 'empty formats' => array( - 'default' => array( - array( + // [default[], overriding[], expected[]] + return [ + 'empty formats' => [ + 'default' => [ + [ 'type' => 0, 'flags' => 0, 'html' => '', 'cli' => '', 'function' => '', - ), - ), - 'overriding' => array( - array(), - ), - 'expected' => array( - array( + ], + ], + 'overriding' => [ + [], + ], + 'expected' => [ + [ 'type' => 0, 'flags' => 0, 'html' => '', 'cli' => '', 'function' => '', - ), - ), - ), - 'no flags' => array( - 'default' => array( - array( + ], + ], + ], + 'no flags' => [ + 'default' => [ + [ 'type' => 0, 'flags' => 0, 'html' => 'html', 'cli' => 'cli', - ), - array( + ], + [ 'type' => 0, 'flags' => 1, 'html' => 'html', 'cli' => 'cli', - ), - ), - 'overriding' => array( - array( + ], + ], + 'overriding' => [ + [ 'type' => 0, 'html' => 'new html', 'cli' => 'new cli', - ), - ), - 'expected' => array( - array( + ], + ], + 'expected' => [ + [ 'type' => 0, 'flags' => 0, 'html' => 'new html', 'cli' => 'new cli', 'function' => '', - ), - array( + ], + [ 'type' => 0, 'flags' => 1, 'html' => 'html', 'cli' => 'cli', - ), - ), - ), - 'with flags' => array( - 'default' => array( - array( + ], + ], + ], + 'with flags' => [ + 'default' => [ + [ 'type' => -1, 'flags' => 0, 'html' => 'html', 'cli' => 'cli', - ), - array( + ], + [ 'type' => 0, 'flags' => 0, 'html' => 'html', 'cli' => 'cli', - ), - array( + ], + [ 'type' => 0, 'flags' => 1, 'html' => 'html', 'cli' => 'cli', - ), - ), - 'overriding' => array( - array( + ], + ], + 'overriding' => [ + [ 'type' => 0, 'flags' => 0, 'html' => 'new html', 'cli' => 'new cli', - ), - ), - 'expected' => array( - array( + ], + ], + 'expected' => [ + [ 'type' => -1, 'flags' => 0, 'html' => 'html', 'cli' => 'cli', - ), - array( + ], + [ 'type' => 0, 'flags' => 0, 'html' => 'new html', 'cli' => 'new cli', 'function' => '', - ), - array( + ], + [ 'type' => 0, 'flags' => 1, 'html' => 'html', 'cli' => 'cli', - ), - ), - ), - 'with extra formats' => array( - 'default' => array( - array( + ], + ], + ], + 'with extra formats' => [ + 'default' => [ + [ 'type' => 0, 'flags' => 0, 'html' => 'html', 'cli' => 'cli', - ), - ), - 'overriding' => array( - array( + ], + ], + 'overriding' => [ + [ 'type' => 0, 'flags' => 1, 'html' => 'new html', 'cli' => 'new cli', - ), - array( + ], + [ 'type' => 1, 'html' => 'new html', 'cli' => 'new cli', - ), - array( + ], + [ 'type' => 1, 'flags' => 1, 'html' => 'new html', 'cli' => 'new cli', - ), - ), - 'expected' => array( - array( + ], + ], + 'expected' => [ + [ 'type' => 0, 'flags' => 0, 'html' => 'html', 'cli' => 'cli', - ), - array( + ], + [ 'type' => 0, 'flags' => 1, 'html' => 'new html', 'cli' => 'new cli', 'function' => '', - ), - array( + ], + [ 'type' => 1, 'flags' => 0, 'html' => 'new html', 'cli' => 'new cli', 'function' => '', - ), - array( + ], + [ 'type' => 1, 'flags' => 1, 'html' => 'new html', 'cli' => 'new cli', 'function' => '', - ), - ), - ) - ); + ], + ], + ], + ]; } /** - * @dataProvider formatQueries - * * @param mixed $query * @param mixed $text * @param mixed $cli * @param mixed $html + * + * @dataProvider formatQueries */ - public function testFormat($query, $text, $cli, $html, array $options = array()) + public function testFormat($query, $text, $cli, $html, array $options = []) { // Test TEXT format - $this->assertEquals($text, Formatter::format($query, array('type' => 'text') + $options), 'Text formatting failed.'); + $this->assertEquals($text, Formatter::format($query, ['type' => 'text'] + $options), 'Text formatting failed.'); // Test CLI format - $this->assertEquals($cli, Formatter::format($query, array('type' => 'cli') + $options), 'CLI formatting failed.'); + $this->assertEquals($cli, Formatter::format($query, ['type' => 'cli'] + $options), 'CLI formatting failed.'); // Test HTML format - $this->assertEquals($html, Formatter::format($query, array('type' => 'html') + $options), 'HTML formatting failed.'); + $this->assertEquals($html, Formatter::format($query, ['type' => 'html'] + $options), 'HTML formatting failed.'); } public function formatQueries() { - return array( - 'empty' => array( + return [ + 'empty' => [ 'query' => '', 'text' => '', 'cli' => "\x1b[0m", 'html' => '', - ), - 'minimal' => array( + ], + 'minimal' => [ 'query' => 'select 1', 'text' => 'SELECT' . "\n" . ' 1', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[92m1" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[92m1\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . ' <span class="sql-number">1</span>', - ), - 'simply' => array( + ], + 'simply' => [ 'query' => 'select * from tbl where 1', 'text' => 'SELECT' . "\n" . ' *' . "\n" . @@ -278,20 +280,20 @@ class FormatterTest extends TestCase ' tbl' . "\n" . 'WHERE' . "\n" . ' 1', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[39m*" . "\n" . - "\x1b[35mFROM" . "\n" . - " \x1b[39mtbl" . "\n" . - "\x1b[35mWHERE" . "\n" . - " \x1b[92m1" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . - ' *' . '<br/>' . - '<span class="sql-reserved">FROM</span>' . '<br/>' . - ' tbl' . '<br/>' . - '<span class="sql-reserved">WHERE</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[39m*\n" . + "\x1b[35mFROM\n" . + " \x1b[39mtbl\n" . + "\x1b[35mWHERE\n" . + " \x1b[92m1\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . + ' *<br/>' . + '<span class="sql-reserved">FROM</span><br/>' . + ' tbl<br/>' . + '<span class="sql-reserved">WHERE</span><br/>' . ' <span class="sql-number">1</span>', - ), - 'typical' => array( + ], + 'typical' => [ 'query' => 'SELECT id, if(id=1,"Si","No") from `tbl` where id = 0 or id = 1 group by id order by id desc limit 1 offset 0', 'text' => 'SELECT' . "\n" . ' id,' . "\n" . @@ -306,34 +308,34 @@ class FormatterTest extends TestCase ' id' . "\n" . 'DESC' . "\n" . 'LIMIT 1 OFFSET 0', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[39mid," . "\n" . - " \x1b[35mIF\x1b[39m(id = \x1b[92m1\x1b[39m, \x1b[91m\"Si\"\x1b[39m, \x1b[91m\"No\"\x1b[39m)" . "\n" . - "\x1b[35mFROM" . "\n" . - " \x1b[36m`tbl`" . "\n" . - "\x1b[35mWHERE" . "\n" . - " \x1b[39mid = \x1b[92m0 \x1b[35mOR \x1b[39mid = \x1b[92m1" . "\n" . - "\x1b[35mGROUP BY" . "\n" . - " \x1b[39mid" . "\n" . - "\x1b[35mORDER BY" . "\n" . - " \x1b[39mid" . "\n" . - "\x1b[35mDESC" . "\n" . - "LIMIT \x1b[92m1 \x1b[95mOFFSET \x1b[92m0" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . - ' id,' . '<br/>' . - ' <span class="sql-reserved">IF</span>(id = <span class="sql-number">1</span>, <span class="sql-string">"Si"</span>, <span class="sql-string">"No"</span>)' . '<br/>' . - '<span class="sql-reserved">FROM</span>' . '<br/>' . - ' <span class="sql-variable">`tbl`</span>' . '<br/>' . - '<span class="sql-reserved">WHERE</span>' . '<br/>' . - ' id = <span class="sql-number">0</span> <span class="sql-reserved">OR</span> id = <span class="sql-number">1</span>' . '<br/>' . - '<span class="sql-reserved">GROUP BY</span>' . '<br/>' . - ' id' . '<br/>' . - '<span class="sql-reserved">ORDER BY</span>' . '<br/>' . - ' id' . '<br/>' . - '<span class="sql-reserved">DESC</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[39mid,\n" . + " \x1b[35mIF\x1b[39m(id = \x1b[92m1\x1b[39m, \x1b[91m\"Si\"\x1b[39m, \x1b[91m\"No\"\x1b[39m)\n" . + "\x1b[35mFROM\n" . + " \x1b[36m`tbl`\n" . + "\x1b[35mWHERE\n" . + " \x1b[39mid = \x1b[92m0 \x1b[35mOR \x1b[39mid = \x1b[92m1\n" . + "\x1b[35mGROUP BY\n" . + " \x1b[39mid\n" . + "\x1b[35mORDER BY\n" . + " \x1b[39mid\n" . + "\x1b[35mDESC\n" . + "LIMIT \x1b[92m1 \x1b[95mOFFSET \x1b[92m0\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . + ' id,<br/>' . + ' <span class="sql-reserved">IF</span>(id = <span class="sql-number">1</span>, <span class="sql-string">"Si"</span>, <span class="sql-string">"No"</span>)<br/>' . + '<span class="sql-reserved">FROM</span><br/>' . + ' <span class="sql-variable">`tbl`</span><br/>' . + '<span class="sql-reserved">WHERE</span><br/>' . + ' id = <span class="sql-number">0</span> <span class="sql-reserved">OR</span> id = <span class="sql-number">1</span><br/>' . + '<span class="sql-reserved">GROUP BY</span><br/>' . + ' id<br/>' . + '<span class="sql-reserved">ORDER BY</span><br/>' . + ' id<br/>' . + '<span class="sql-reserved">DESC</span><br/>' . '<span class="sql-reserved">LIMIT</span> <span class="sql-number">1</span> <span class="sql-keyword">OFFSET</span> <span class="sql-number">0</span>', - ), - 'comments' => array( + ], + 'comments' => [ 'query' => 'select /* Comment */ *' . "\n" . 'from tbl # Comment' . "\n" . 'where 1 -- Comment', @@ -343,20 +345,20 @@ class FormatterTest extends TestCase ' tbl # Comment' . "\n" . 'WHERE' . "\n" . ' 1 -- Comment', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[37m/* Comment */ \x1b[39m*" . "\n" . - "\x1b[35mFROM" . "\n" . - " \x1b[39mtbl \x1b[37m# Comment" . "\n" . - "\x1b[35mWHERE" . "\n" . - " \x1b[92m1 \x1b[37m-- Comment" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . - ' <span class="sql-comment">/* Comment */</span> *' . '<br/>' . - '<span class="sql-reserved">FROM</span>' . '<br/>' . - ' tbl <span class="sql-comment"># Comment</span>' . '<br/>' . - '<span class="sql-reserved">WHERE</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[37m/* Comment */ \x1b[39m*\n" . + "\x1b[35mFROM\n" . + " \x1b[39mtbl \x1b[37m# Comment\n" . + "\x1b[35mWHERE\n" . + " \x1b[92m1 \x1b[37m-- Comment\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . + ' <span class="sql-comment">/* Comment */</span> *<br/>' . + '<span class="sql-reserved">FROM</span><br/>' . + ' tbl <span class="sql-comment"># Comment</span><br/>' . + '<span class="sql-reserved">WHERE</span><br/>' . ' <span class="sql-number">1</span> <span class="sql-comment">-- Comment</span>', - ), - 'strip comments' => array( + ], + 'strip comments' => [ 'query' => 'select /* Comment */ *' . "\n" . 'from tbl # Comment' . "\n" . 'where 1 -- Comment', @@ -366,41 +368,41 @@ class FormatterTest extends TestCase ' tbl' . "\n" . 'WHERE' . "\n" . ' 1', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[39m*" . "\n" . - "\x1b[35mFROM" . "\n" . - " \x1b[39mtbl" . "\n" . - "\x1b[35mWHERE" . "\n" . - " \x1b[92m1" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . - ' *' . '<br/>' . - '<span class="sql-reserved">FROM</span>' . '<br/>' . - ' tbl' . '<br/>' . - '<span class="sql-reserved">WHERE</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[39m*\n" . + "\x1b[35mFROM\n" . + " \x1b[39mtbl\n" . + "\x1b[35mWHERE\n" . + " \x1b[92m1\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . + ' *<br/>' . + '<span class="sql-reserved">FROM</span><br/>' . + ' tbl<br/>' . + '<span class="sql-reserved">WHERE</span><br/>' . ' <span class="sql-number">1</span>', - 'options' => array( + 'options' => [ 'remove_comments' => true, - ), - ), - 'keywords' => array( + ], + ], + 'keywords' => [ 'query' => 'select hex("1")', 'text' => 'SELECT' . "\n" . ' HEX("1")', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[95mHEX\x1b[39m(\x1b[91m\"1\"\x1b[39m)" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[95mHEX\x1b[39m(\x1b[91m\"1\"\x1b[39m)\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . ' <span class="sql-keyword">HEX</span>(<span class="sql-string">"1"</span>)', - ), - 'distinct count' => array( + ], + 'distinct count' => [ 'query' => 'select distinct count(*)', 'text' => 'SELECT DISTINCT' . "\n" . ' COUNT(*)', - 'cli' => "\x1b[35mSELECT DISTINCT" . "\n" . - " \x1b[95mCOUNT\x1b[39m(*)" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span> <span class="sql-reserved">DISTINCT</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT DISTINCT\n" . + " \x1b[95mCOUNT\x1b[39m(*)\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span> <span class="sql-reserved">DISTINCT</span><br/>' . ' <span class="sql-keyword">COUNT</span>(*)', - ), - 'create procedure' => array( + ], + 'create procedure' => [ 'query' => 'create procedure test_procedure() begin from tbl select *; end', 'text' => 'CREATE PROCEDURE test_procedure()' . "\n" . 'BEGIN' . "\n" . @@ -410,65 +412,65 @@ class FormatterTest extends TestCase ' *;' . "\n" . 'END', 'cli' => "\x1b[35mCREATE PROCEDURE \x1b[39mtest_procedure()\n" . - "\x1b[95mBEGIN" . "\n" . - " \x1b[35mFROM" . "\n" . - " \x1b[39mtbl" . "\n" . - " \x1b[35mSELECT" . "\n" . + "\x1b[95mBEGIN\n" . + " \x1b[35mFROM\n" . + " \x1b[39mtbl\n" . + " \x1b[35mSELECT\n" . " \x1b[39m*;\n" . - "\x1b[95mEND" . "\x1b[0m", - 'html' => '<span class="sql-reserved">CREATE</span> <span class="sql-reserved">PROCEDURE</span> test_procedure()' . '<br/>' . - '<span class="sql-keyword">BEGIN</span>' . '<br/>' . - ' <span class="sql-reserved">FROM</span>' . '<br/>' . - ' tbl' . '<br/>' . - ' <span class="sql-reserved">SELECT</span>' . '<br/>' . - ' *;' . '<br/>' . + "\x1b[95mEND\x1b[0m", + 'html' => '<span class="sql-reserved">CREATE</span> <span class="sql-reserved">PROCEDURE</span> test_procedure()<br/>' . + '<span class="sql-keyword">BEGIN</span><br/>' . + ' <span class="sql-reserved">FROM</span><br/>' . + ' tbl<br/>' . + ' <span class="sql-reserved">SELECT</span><br/>' . + ' *;<br/>' . '<span class="sql-keyword">END</span>', - ), - 'insert' => array( + ], + 'insert' => [ 'query' => 'insert into foo values (0, 0, 0), (1, 1, 1)', 'text' => 'INSERT INTO foo' . "\n" . 'VALUES(0, 0, 0),(1, 1, 1)', - 'cli' => "\x1b[35mINSERT INTO \x1b[39mfoo" . "\n" . - "\x1b[35mVALUES\x1b[39m(\x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m),(\x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m)" . "\x1b[0m", - 'html' => '<span class="sql-reserved">INSERT</span> <span class="sql-reserved">INTO</span> foo' . '<br/>' . + 'cli' => "\x1b[35mINSERT INTO \x1b[39mfoo\n" . + "\x1b[35mVALUES\x1b[39m(\x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m, \x1b[92m0\x1b[39m),(\x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m, \x1b[92m1\x1b[39m)\x1b[0m", + 'html' => '<span class="sql-reserved">INSERT</span> <span class="sql-reserved">INTO</span> foo<br/>' . '<span class="sql-reserved">VALUES</span>(<span class="sql-number">0</span>, <span class="sql-number">0</span>, <span class="sql-number">0</span>),(<span class="sql-number">1</span>, <span class="sql-number">1</span>, <span class="sql-number">1</span>)', - ), - 'string as alias' => array( + ], + 'string as alias' => [ 'query' => 'select "Text" as bar', 'text' => 'SELECT' . "\n" . ' "Text" AS bar', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[91m\"Text\" \x1b[35mAS \x1b[39mbar" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[91m\"Text\" \x1b[35mAS \x1b[39mbar\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . ' <span class="sql-string">"Text"</span> <span class="sql-reserved">AS</span> bar', - ), - 'escape cli' => array( + ], + 'escape cli' => [ 'query' => "select 'text\x1b[33mcolor-inj'", 'text' => 'SELECT' . "\n" . " 'text\x1B[33mcolor-inj'", - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[91m'text\\x1B[33mcolor-inj'" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[91m'text\\x1B[33mcolor-inj'\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . ' <span class="sql-string">\'text' . "\x1b[33m" . 'color-inj\'</span>', - ), - 'escape html' => array( + ], + 'escape html' => [ 'query' => "select '<s>xss' from `<s>xss` , <s>nxss /*s<s>xss*/", 'text' => 'SELECT' . "\n" . ' \'<s>xss\'' . "\n" . 'FROM' . "\n" . ' `<s>xss`,' . "\n" . ' < s > nxss /*s<s>xss*/', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[91m'<s>xss'" . "\n" . - "\x1b[35mFROM" . "\n" . - " \x1b[36m`<s>xss`\x1b[39m," . "\n" . - " < s > nxss \x1b[37m/*s<s>xss*/" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . - ' <span class="sql-string">\'<s>xss\'</span>' . '<br/>' . - '<span class="sql-reserved">FROM</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[91m'<s>xss'\n" . + "\x1b[35mFROM\n" . + " \x1b[36m`<s>xss`\x1b[39m,\n" . + " < s > nxss \x1b[37m/*s<s>xss*/\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . + ' <span class="sql-string">\'<s>xss\'</span><br/>' . + '<span class="sql-reserved">FROM</span><br/>' . ' <span class="sql-variable">`<s>xss`</span>,<br/> < s > nxss <span class="sql-comment">/*s<s>xss*/</span>', - ), - 'create table' => array( + ], + 'create table' => [ 'query' => 'create table if not exists `pma__bookmark` (' . "\n" . '`id` int(11) not null auto_increment,' . "\n" . '`dbase` varchar(255) not null default "",' . "\n" . @@ -483,29 +485,29 @@ class FormatterTest extends TestCase ' `label` VARCHAR(255) COLLATE utf8_general_ci NOT NULL DEFAULT "",' . "\n" . ' `query` TEXT NOT NULL,' . "\n" . ' PRIMARY KEY(`id`)', - 'cli' => "\x1b[35mCREATE TABLE IF NOT EXISTS \x1b[36m`pma__bookmark`\x1b[39m(" . "\n" . - " \x1b[36m`id` \x1b[35mINT\x1b[39m(\x1b[92m11\x1b[39m) \x1b[35mNOT NULL \x1b[95mAUTO_INCREMENT\x1b[39m," . "\n" . - " \x1b[36m`dbase` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m," . "\n" . - " \x1b[36m`user` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m," . "\n" . - " \x1b[36m`label` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mCOLLATE \x1b[39mutf8_general_ci \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m," . "\n" . - " \x1b[36m`query` \x1b[95mTEXT \x1b[35mNOT NULL\x1b[39m," . "\n" . - " \x1b[35mPRIMARY KEY\x1b[39m(\x1b[36m`id`\x1b[39m)" . "\x1b[0m", - 'html' => '<span class="sql-reserved">CREATE</span> <span class="sql-reserved">TABLE</span> <span class="sql-reserved">IF NOT EXISTS</span> <span class="sql-variable">`pma__bookmark`</span>(' . '<br/>' . - ' <span class="sql-variable">`id`</span> <span class="sql-reserved">INT</span>(<span class="sql-number">11</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-keyword">AUTO_INCREMENT</span>,' . '<br/>' . - ' <span class="sql-variable">`dbase`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,' . '<br/>' . - ' <span class="sql-variable">`user`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,' . '<br/>' . - ' <span class="sql-variable">`label`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">COLLATE</span> utf8_general_ci <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,' . '<br/>' . - ' <span class="sql-variable">`query`</span> <span class="sql-keyword">TEXT</span> <span class="sql-reserved">NOT NULL</span>,' . '<br/>' . + 'cli' => "\x1b[35mCREATE TABLE IF NOT EXISTS \x1b[36m`pma__bookmark`\x1b[39m(\n" . + " \x1b[36m`id` \x1b[35mINT\x1b[39m(\x1b[92m11\x1b[39m) \x1b[35mNOT NULL \x1b[95mAUTO_INCREMENT\x1b[39m,\n" . + " \x1b[36m`dbase` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m,\n" . + " \x1b[36m`user` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m,\n" . + " \x1b[36m`label` \x1b[35mVARCHAR\x1b[39m(\x1b[92m255\x1b[39m) \x1b[35mCOLLATE \x1b[39mutf8_general_ci \x1b[35mNOT NULL DEFAULT \x1b[91m\"\"\x1b[39m,\n" . + " \x1b[36m`query` \x1b[95mTEXT \x1b[35mNOT NULL\x1b[39m,\n" . + " \x1b[35mPRIMARY KEY\x1b[39m(\x1b[36m`id`\x1b[39m)\x1b[0m", + 'html' => '<span class="sql-reserved">CREATE</span> <span class="sql-reserved">TABLE</span> <span class="sql-reserved">IF NOT EXISTS</span> <span class="sql-variable">`pma__bookmark`</span>(<br/>' . + ' <span class="sql-variable">`id`</span> <span class="sql-reserved">INT</span>(<span class="sql-number">11</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-keyword">AUTO_INCREMENT</span>,<br/>' . + ' <span class="sql-variable">`dbase`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,<br/>' . + ' <span class="sql-variable">`user`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,<br/>' . + ' <span class="sql-variable">`label`</span> <span class="sql-reserved">VARCHAR</span>(<span class="sql-number">255</span>) <span class="sql-reserved">COLLATE</span> utf8_general_ci <span class="sql-reserved">NOT NULL</span> <span class="sql-reserved">DEFAULT</span> <span class="sql-string">""</span>,<br/>' . + ' <span class="sql-variable">`query`</span> <span class="sql-keyword">TEXT</span> <span class="sql-reserved">NOT NULL</span>,<br/>' . ' <span class="sql-reserved">PRIMARY KEY</span>(<span class="sql-variable">`id`</span>)', - ), - 'join' => array( + ], + 'join' => [ 'query' => 'join tbl2 on c1=c2', 'text' => 'JOIN tbl2 ON c1 = c2', 'cli' => "\x1b[35mJOIN \x1b[39mtbl2 \x1b[35mON \x1b[39mc1 = c2" . "\x1b[0m", 'html' => '<span class="sql-reserved">JOIN</span> tbl2 <span class="sql-reserved">ON</span> c1 = c2', - ), - 'named param' => array( + ], + 'named param' => [ 'query' => 'select * from tbl where col = :param', 'text' => 'SELECT' . "\n" . ' *' . "\n" . @@ -513,20 +515,20 @@ class FormatterTest extends TestCase ' tbl' . "\n" . 'WHERE' . "\n" . ' col = :param', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[39m*" . "\n" . - "\x1b[35mFROM" . "\n" . - " \x1b[39mtbl" . "\n" . - "\x1b[35mWHERE" . "\n" . - " \x1b[39mcol = \x1b[31m:param" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . - ' *' . '<br/>' . - '<span class="sql-reserved">FROM</span>' . '<br/>' . - ' tbl' . '<br/>' . - '<span class="sql-reserved">WHERE</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[39m*\n" . + "\x1b[35mFROM\n" . + " \x1b[39mtbl\n" . + "\x1b[35mWHERE\n" . + " \x1b[39mcol = \x1b[31m:param\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . + ' *<br/>' . + '<span class="sql-reserved">FROM</span><br/>' . + ' tbl<br/>' . + '<span class="sql-reserved">WHERE</span><br/>' . ' col = <span class="sql-parameter">:param</span>', - ), - 'anon param' => array( + ], + 'anon param' => [ 'query' => 'select * from tbl where col = ?', 'text' => 'SELECT' . "\n" . ' *' . "\n" . @@ -534,19 +536,19 @@ class FormatterTest extends TestCase ' tbl' . "\n" . 'WHERE' . "\n" . ' col = ?', - 'cli' => "\x1b[35mSELECT" . "\n" . - " \x1b[39m*" . "\n" . - "\x1b[35mFROM" . "\n" . - " \x1b[39mtbl" . "\n" . - "\x1b[35mWHERE" . "\n" . - " \x1b[39mcol = \x1b[31m?" . "\x1b[0m", - 'html' => '<span class="sql-reserved">SELECT</span>' . '<br/>' . - ' *' . '<br/>' . - '<span class="sql-reserved">FROM</span>' . '<br/>' . - ' tbl' . '<br/>' . - '<span class="sql-reserved">WHERE</span>' . '<br/>' . + 'cli' => "\x1b[35mSELECT\n" . + " \x1b[39m*\n" . + "\x1b[35mFROM\n" . + " \x1b[39mtbl\n" . + "\x1b[35mWHERE\n" . + " \x1b[39mcol = \x1b[31m?\x1b[0m", + 'html' => '<span class="sql-reserved">SELECT</span><br/>' . + ' *<br/>' . + '<span class="sql-reserved">FROM</span><br/>' . + ' tbl<br/>' . + '<span class="sql-reserved">WHERE</span><br/>' . ' col = <span class="sql-parameter">?</span>', - ) - ); + ], + ]; } } diff --git a/tests/Utils/MiscTest.php b/tests/Utils/MiscTest.php index 3abc1cb..480d687 100644 --- a/tests/Utils/MiscTest.php +++ b/tests/Utils/MiscTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; @@ -9,10 +10,10 @@ use PhpMyAdmin\SqlParser\Utils\Misc; class MiscTest extends TestCase { /** - * @dataProvider getAliasesProvider - * * @param mixed $query * @param mixed $db + * + * @dataProvider getAliasesProvider */ public function testGetAliases($query, $db, array $expected) { @@ -24,104 +25,104 @@ class MiscTest extends TestCase public function getAliasesProvider() { - return array( - array( + return [ + [ 'select * from (select 1) tbl', 'mydb', - array(), - ), - array( + [], + ], + [ 'select i.name as `n`,abcdef gh from qwerty i', 'mydb', - array( - 'mydb' => array( + [ + 'mydb' => [ 'alias' => null, - 'tables' => array( - 'qwerty' => array( + 'tables' => [ + 'qwerty' => [ 'alias' => 'i', - 'columns' => array( + 'columns' => [ 'name' => 'n', 'abcdef' => 'gh', - ), - ), - ), - ), - ), - ), - array( + ], + ], + ], + ], + ], + ], + [ 'select film_id id,title from film', 'sakila', - array( - 'sakila' => array( + [ + 'sakila' => [ 'alias' => null, - 'tables' => array( - 'film' => array( + 'tables' => [ + 'film' => [ 'alias' => null, - 'columns' => array( + 'columns' => [ 'film_id' => 'id', - ), - ), - ), - ), - ), - ), - array( + ], + ], + ], + ], + ], + ], + [ 'select `sakila`.`A`.`actor_id` as aid,`F`.`film_id` `fid`,' . 'last_update updated from `sakila`.actor A join `film_actor` as ' . '`F` on F.actor_id = A.`actor_id`', 'sakila', - array( - 'sakila' => array( + [ + 'sakila' => [ 'alias' => null, - 'tables' => array( - 'film_actor' => array( + 'tables' => [ + 'film_actor' => [ 'alias' => 'F', - 'columns' => array( + 'columns' => [ 'film_id' => 'fid', 'last_update' => 'updated', - ), - ), - 'actor' => array( + ], + ], + 'actor' => [ 'alias' => 'A', - 'columns' => array( + 'columns' => [ 'actor_id' => 'aid', 'last_update' => 'updated', - ), - ), - ), - ), - ), - ), - array( + ], + ], + ], + ], + ], + ], + [ 'SELECT film_id FROM (SELECT * FROM film) as f;', 'sakila', - array(), - ), - array( + [], + ], + [ '', null, - array(), - ), - array( + [], + ], + [ 'SELECT 1', null, - array(), - ), - array( + [], + ], + [ 'SELECT * FROM orders AS ord WHERE 1', 'db', - array( - 'db' => array( + [ + 'db' => [ 'alias' => null, - 'tables' => array( - 'orders' => array( + 'tables' => [ + 'orders' => [ 'alias' => 'ord', - 'columns' => array(), - ), - ), - ), - ), - ) - ); + 'columns' => [], + ], + ], + ], + ], + ], + ]; } } diff --git a/tests/Utils/QueryTest.php b/tests/Utils/QueryTest.php index f4676ec..5639610 100644 --- a/tests/Utils/QueryTest.php +++ b/tests/Utils/QueryTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; @@ -9,10 +10,10 @@ use PhpMyAdmin\SqlParser\Utils\Query; class QueryTest extends TestCase { /** - * @dataProvider getFlagsProvider - * * @param mixed $query * @param mixed $expected + * + * @dataProvider getFlagsProvider */ public function testGetFlags($query, $expected) { @@ -25,257 +26,257 @@ class QueryTest extends TestCase public function getFlagsProvider() { - return array( - array( + return [ + [ 'ALTER TABLE DROP col', - array( + [ 'reload' => true, 'querytype' => 'ALTER', - ), - ), - array( + ], + ], + [ 'CALL test()', - array( + [ 'is_procedure' => true, 'querytype' => 'CALL', - ), - ), - array( + ], + ], + [ 'CREATE TABLE tbl (id INT)', - array( + [ 'reload' => true, 'querytype' => 'CREATE', - ), - ), - array( + ], + ], + [ 'CHECK TABLE tbl', - array( + [ 'is_maint' => true, 'querytype' => 'CHECK', - ), - ), - array( + ], + ], + [ 'DELETE FROM tbl', - array( + [ 'is_affected' => true, 'is_delete' => true, 'querytype' => 'DELETE', - ), - ), - array( + ], + ], + [ 'DROP VIEW v', - array( + [ 'reload' => true, 'querytype' => 'DROP', - ), - ), - array( + ], + ], + [ 'DROP DATABASE db', - array( + [ 'drop_database' => true, 'reload' => true, 'querytype' => 'DROP', - ), - ), - array( + ], + ], + [ 'EXPLAIN tbl', - array( + [ 'is_explain' => true, 'querytype' => 'EXPLAIN', - ), - ), - array( + ], + ], + [ 'LOAD DATA INFILE \'/tmp/test.txt\' INTO TABLE test', - array( + [ 'is_affected' => true, 'is_insert' => true, 'querytype' => 'LOAD', - ), - ), - array( + ], + ], + [ 'INSERT INTO tbl VALUES (1)', - array( + [ 'is_affected' => true, 'is_insert' => true, 'querytype' => 'INSERT', - ), - ), - array( + ], + ], + [ 'REPLACE INTO tbl VALUES (2)', - array( + [ 'is_affected' => true, 'is_replace' => true, 'is_insert' => true, 'querytype' => 'REPLACE', - ), - ), - array( + ], + ], + [ 'SELECT 1', - array( + [ 'is_select' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT * FROM tbl', - array( + [ 'is_select' => true, 'select_from' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT DISTINCT * FROM tbl LIMIT 0, 10 ORDER BY id', - array( + [ 'distinct' => true, 'is_select' => true, 'select_from' => true, 'limit' => true, 'order' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT * FROM actor GROUP BY actor_id', - array( + [ 'is_group' => true, 'is_select' => true, 'select_from' => true, 'group' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT col1, col2 FROM table1 PROCEDURE ANALYSE(10, 2000);', - array( + [ 'is_analyse' => true, 'is_select' => true, 'select_from' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT * FROM tbl INTO OUTFILE "/tmp/export.txt"', - array( + [ 'is_export' => true, 'is_select' => true, 'select_from' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT COUNT(id), SUM(id) FROM tbl', - array( + [ 'is_count' => true, 'is_func' => true, 'is_select' => true, 'select_from' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT (SELECT "foo")', - array( + [ 'is_select' => true, 'is_subquery' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT * FROM customer HAVING store_id = 2;', - array( + [ 'is_select' => true, 'select_from' => true, 'is_group' => true, 'having' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT * FROM table1 INNER JOIN table2 ON table1.id=table2.id;', - array( + [ 'is_select' => true, 'select_from' => true, 'join' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SHOW CREATE TABLE tbl', - array( + [ 'is_show' => true, 'querytype' => 'SHOW', - ), - ), - array( + ], + ], + [ 'UPDATE tbl SET id = 1', - array( + [ 'is_affected' => true, 'querytype' => 'UPDATE', - ), - ), - array( + ], + ], + [ 'ANALYZE TABLE tbl', - array( + [ 'is_maint' => true, 'querytype' => 'ANALYZE', - ), - ), - array( + ], + ], + [ 'CHECKSUM TABLE tbl', - array( + [ 'is_maint' => true, 'querytype' => 'CHECKSUM', - ), - ), - array( + ], + ], + [ 'OPTIMIZE TABLE tbl', - array( + [ 'is_maint' => true, 'querytype' => 'OPTIMIZE', - ), - ), - array( + ], + ], + [ 'REPAIR TABLE tbl', - array( + [ 'is_maint' => true, 'querytype' => 'REPAIR', - ), - ), - array( + ], + ], + [ '(SELECT a FROM t1 WHERE a=10 AND B=1 ORDER BY a LIMIT 10) ' . 'UNION ' . '(SELECT a FROM t2 WHERE a=11 AND B=2 ORDER BY a LIMIT 10);', - array( + [ 'is_select' => true, 'select_from' => true, 'limit' => true, 'order' => true, 'union' => true, 'querytype' => 'SELECT', - ), - ), - array( + ], + ], + [ 'SELECT * FROM orders AS ord WHERE 1', - array( + [ 'querytype' => 'SELECT', 'is_select' => true, 'select_from' => true, - ), - ), - array( + ], + ], + [ 'SET NAMES \'latin\'', - array( + [ 'querytype' => 'SET', - ), - ) - ); + ], + ], + ]; } public function testGetAll() { $this->assertEquals( - array( + [ 'distinct' => false, 'drop_database' => false, 'group' => false, @@ -303,7 +304,7 @@ class QueryTest extends TestCase 'reload' => false, 'select_from' => false, 'union' => false, - ), + ], Query::getAll('') ); @@ -313,21 +314,21 @@ class QueryTest extends TestCase $this->assertEquals( array_merge( Query::getFlags($parser->statements[0], true), - array( + [ 'parser' => $parser, 'statement' => $parser->statements[0], - 'select_expr' => array('*'), - 'select_tables' => array( - array( + 'select_expr' => ['*'], + 'select_tables' => [ + [ 'actor', null, - ), - array( + ], + [ 'film', 'sakila2', - ), - ) - ) + ], + ], + ] ), Query::getAll($query) ); @@ -337,21 +338,21 @@ class QueryTest extends TestCase $this->assertEquals( array_merge( Query::getFlags($parser->statements[0], true), - array( + [ 'parser' => $parser, 'statement' => $parser->statements[0], - 'select_expr' => array('*'), - 'select_tables' => array( - array( + 'select_expr' => ['*'], + 'select_tables' => [ + [ 'actor', 'sakila', - ), - array( + ], + [ 'film', null, - ), - ) - ) + ], + ], + ] ), Query::getAll($query) ); @@ -361,17 +362,17 @@ class QueryTest extends TestCase $this->assertEquals( array_merge( Query::getFlags($parser->statements[0], true), - array( + [ 'parser' => $parser, 'statement' => $parser->statements[0], - 'select_expr' => array(), - 'select_tables' => array( - array( + 'select_expr' => [], + 'select_tables' => [ + [ 'actor', 'sakila', - ), - ), - ) + ], + ], + ] ), Query::getAll($query) ); @@ -381,24 +382,24 @@ class QueryTest extends TestCase $this->assertEquals( array_merge( Query::getFlags($parser->statements[0], true), - array( + [ 'parser' => $parser, 'statement' => $parser->statements[0], - 'select_expr' => array( + 'select_expr' => [ 'CASE WHEN 2 IS NULL THEN "this is true" ELSE "this is false" END', - ), - 'select_tables' => array(), - ) + ], + 'select_tables' => [], + ] ), Query::getAll($query) ); } /** - * @dataProvider getTablesProvider - * * @param mixed $query * @param mixed $expected + * + * @dataProvider getTablesProvider */ public function testGetTables($query, $expected) { @@ -411,42 +412,42 @@ class QueryTest extends TestCase public function getTablesProvider() { - return array( - array( + return [ + [ 'INSERT INTO tbl(`id`, `name`) VALUES (1, "Name")', - array('`tbl`') - ), - array( + ['`tbl`'], + ], + [ 'UPDATE tbl SET id = 0', - array('`tbl`') - ), - array( + ['`tbl`'], + ], + [ 'DELETE FROM tbl WHERE id < 10', - array('`tbl`') - ), - array( + ['`tbl`'], + ], + [ 'TRUNCATE tbl', - array('`tbl`') - ), - array( + ['`tbl`'], + ], + [ 'DROP VIEW v', - array() - ), - array( + [], + ], + [ 'DROP TABLE tbl1, tbl2', - array( + [ '`tbl1`', '`tbl2`', - ), - ), - array( + ], + ], + [ 'RENAME TABLE a TO b, c TO d', - array( + [ '`a`', - '`c`' - ) - ) - ); + '`c`', + ], + ], + ]; } public function testGetClause() @@ -614,7 +615,7 @@ class QueryTest extends TestCase public function testReplaceClauses() { - $this->assertEquals('', Query::replaceClauses(null, null, array())); + $this->assertEquals('', Query::replaceClauses(null, null, [])); $parser = new Parser('SELECT *, (SELECT 1) FROM film LIMIT 0, 10;'); $this->assertEquals( @@ -622,12 +623,12 @@ class QueryTest extends TestCase Query::replaceClauses( $parser->statements[0], $parser->list, - array( - array( + [ + [ 'WHERE', 'WHERE film_id > 0', - ) - ) + ], + ] ) ); @@ -648,20 +649,20 @@ class QueryTest extends TestCase Query::replaceClauses( $parser->statements[0], $parser->list, - array( - array( + [ + [ 'FROM', 'FROM city AS c', - ), - array( + ], + [ 'WHERE', '', - ), - array( + ], + [ 'LIMIT', 'LIMIT 0, 10', - ) - ) + ], + ] ) ); } diff --git a/tests/Utils/RoutineTest.php b/tests/Utils/RoutineTest.php index c988b91..90ba0b7 100644 --- a/tests/Utils/RoutineTest.php +++ b/tests/Utils/RoutineTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; @@ -9,9 +10,9 @@ use PhpMyAdmin\SqlParser\Utils\Routine; class RoutineTest extends TestCase { /** - * @dataProvider getReturnTypeProvider - * * @param mixed $def + * + * @dataProvider getReturnTypeProvider */ public function testGetReturnType($def, array $expected) { @@ -20,94 +21,94 @@ class RoutineTest extends TestCase public function getReturnTypeProvider() { - return array( - array( + return [ + [ '', - array( + [ '', '', '', '', '', - ), - ), - array( + ], + ], + [ 'TEXT', - array( + [ '', '', 'TEXT', '', '', - ), - ), - array( + ], + ], + [ 'INT(20)', - array( + [ '', '', 'INT', '20', '', - ), - ), - array( + ], + ], + [ 'INT UNSIGNED', - array( + [ '', '', 'INT', '', 'UNSIGNED', - ), - ), - array( + ], + ], + [ 'VARCHAR(1) CHARSET utf8', - array( + [ '', '', 'VARCHAR', '1', 'utf8', - ), - ), - array( + ], + ], + [ 'ENUM(\'a\', \'b\') CHARSET latin1', - array( + [ '', '', 'ENUM', '\'a\',\'b\'', 'latin1', - ), - ), - array( + ], + ], + [ 'DECIMAL(5,2) UNSIGNED ZEROFILL', - array( + [ '', '', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL', - ), - ), - array( + ], + ], + [ 'SET(\'test\'\'esc"\', \'more\\\'esc\')', - array( + [ '', '', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', '', - ), - ) - ); + ], + ], + ]; } /** - * @dataProvider getParameterProvider - * * @param mixed $def + * + * @dataProvider getParameterProvider */ public function testGetParameter($def, array $expected) { @@ -116,94 +117,94 @@ class RoutineTest extends TestCase public function getParameterProvider() { - return array( - array( + return [ + [ '', - array( + [ '', '', '', '', '', - ), - ), - array( + ], + ], + [ '`foo` TEXT', - array( + [ '', 'foo', 'TEXT', '', '', - ), - ), - array( + ], + ], + [ '`foo` INT(20)', - array( + [ '', 'foo', 'INT', '20', '', - ), - ), - array( + ], + ], + [ 'IN `fo``fo` INT UNSIGNED', - array( + [ 'IN', 'fo`fo', 'INT', '', 'UNSIGNED', - ), - ), - array( + ], + ], + [ 'OUT bar VARCHAR(1) CHARSET utf8', - array( + [ 'OUT', 'bar', 'VARCHAR', '1', 'utf8', - ), - ), - array( + ], + ], + [ '`"baz\'\'` ENUM(\'a\', \'b\') CHARSET latin1', - array( + [ '', '"baz\'\'', 'ENUM', '\'a\',\'b\'', 'latin1', - ), - ), - array( + ], + ], + [ 'INOUT `foo` DECIMAL(5,2) UNSIGNED ZEROFILL', - array( + [ 'INOUT', 'foo', 'DECIMAL', '5,2', 'UNSIGNED ZEROFILL', - ), - ), - array( + ], + ], + [ '`foo``s func` SET(\'test\'\'esc"\', \'more\\\'esc\')', - array( + [ '', 'foo`s func', 'SET', '\'test\'\'esc"\',\'more\\\'esc\'', '', - ), - ) - ); + ], + ], + ]; } /** - * @dataProvider getParametersProvider - * * @param mixed $query + * + * @dataProvider getParametersProvider */ public function testGetParameters($query, array $expected) { @@ -213,98 +214,98 @@ class RoutineTest extends TestCase public function getParametersProvider() { - return array( - array( + return [ + [ 'CREATE PROCEDURE `foo`() SET @A=0', - array( + [ 'num' => 0, - 'dir' => array(), - 'name' => array(), - 'type' => array(), - 'length' => array(), - 'length_arr' => array(), - 'opts' => array(), - ), - ), - array( + 'dir' => [], + 'name' => [], + 'type' => [], + 'length' => [], + 'length_arr' => [], + 'opts' => [], + ], + ], + [ 'CREATE DEFINER=`user\\`@`somehost``(` FUNCTION `foo```(`baz` INT) BEGIN SELECT NULL; END', - array( + [ 'num' => 1, - 'dir' => array( + 'dir' => [ 0 => '', - ), - 'name' => array( + ], + 'name' => [ 0 => 'baz', - ), - 'type' => array( + ], + 'type' => [ 0 => 'INT', - ), - 'length' => array( + ], + 'length' => [ 0 => '', - ), - 'length_arr' => array( - 0 => array(), - ), - 'opts' => array( + ], + 'length_arr' => [ + 0 => [], + ], + 'opts' => [ 0 => '', - ), - ), - ), - array( + ], + ], + ], + [ 'CREATE PROCEDURE `foo`(IN `baz\\)` INT(25) zerofill unsigned) BEGIN SELECT NULL; END', - array( + [ 'num' => 1, - 'dir' => array( + 'dir' => [ 0 => 'IN', - ), - 'name' => array( + ], + 'name' => [ 0 => 'baz\\)', - ), - 'type' => array( + ], + 'type' => [ 0 => 'INT', - ), - 'length' => array( + ], + 'length' => [ 0 => '25', - ), - 'length_arr' => array( - 0 => array('25'), - ), - 'opts' => array( + ], + 'length_arr' => [ + 0 => ['25'], + ], + 'opts' => [ 0 => 'UNSIGNED ZEROFILL', - ), - ), - ), - array( + ], + ], + ], + [ 'CREATE PROCEDURE `foo`(IN `baz\\` INT(001) zerofill, out bazz varchar(15) charset utf8) ' . 'BEGIN SELECT NULL; END', - array( + [ 'num' => 2, - 'dir' => array( + 'dir' => [ 0 => 'IN', 1 => 'OUT', - ), - 'name' => array( + ], + 'name' => [ 0 => 'baz\\', 1 => 'bazz', - ), - 'type' => array( + ], + 'type' => [ 0 => 'INT', 1 => 'VARCHAR', - ), - 'length' => array( + ], + 'length' => [ 0 => '1', 1 => '15', - ), - 'length_arr' => array( - 0 => array('1'), - 1 => array('15'), - ), - 'opts' => array( + ], + 'length_arr' => [ + 0 => ['1'], + 1 => ['15'], + ], + 'opts' => [ 0 => 'ZEROFILL', 1 => 'utf8', - ), - ), - ) - ); + ], + ], + ], + ]; } } diff --git a/tests/Utils/TableTest.php b/tests/Utils/TableTest.php index ade4929..b71d951 100644 --- a/tests/Utils/TableTest.php +++ b/tests/Utils/TableTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; @@ -9,9 +10,9 @@ use PhpMyAdmin\SqlParser\Utils\Table; class TableTest extends TestCase { /** - * @dataProvider getForeignKeysProvider - * * @param mixed $query + * + * @dataProvider getForeignKeysProvider */ public function testGetForeignKeys($query, array $expected) { @@ -21,12 +22,12 @@ class TableTest extends TestCase public function getForeignKeysProvider() { - return array( - array( + return [ + [ 'CREATE USER test', - array(), - ), - array( + [], + ], + [ 'CREATE TABLE `payment` ( `payment_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `customer_id` smallint(5) unsigned NOT NULL, @@ -43,35 +44,35 @@ class TableTest extends TestCase CONSTRAINT `fk_payment_rental` FOREIGN KEY (`rental_id`) REFERENCES `rental` (`rental_id`) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT `fk_payment_staff` FOREIGN KEY (`staff_id`) REFERENCES `staff` (`staff_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=16050 DEFAULT CHARSET=utf8', - array( - array( + [ + [ 'constraint' => 'fk_payment_customer', - 'index_list' => array('customer_id'), + 'index_list' => ['customer_id'], 'ref_db_name' => null, 'ref_table_name' => 'customer', - 'ref_index_list' => array('customer_id'), + 'ref_index_list' => ['customer_id'], 'on_update' => 'CASCADE', - ), - array( + ], + [ 'constraint' => 'fk_payment_rental', - 'index_list' => array('rental_id'), + 'index_list' => ['rental_id'], 'ref_db_name' => null, 'ref_table_name' => 'rental', - 'ref_index_list' => array('rental_id'), + 'ref_index_list' => ['rental_id'], 'on_delete' => 'SET_NULL', 'on_update' => 'CASCADE', - ), - array( + ], + [ 'constraint' => 'fk_payment_staff', - 'index_list' => array('staff_id'), + 'index_list' => ['staff_id'], 'ref_db_name' => null, 'ref_table_name' => 'staff', - 'ref_index_list' => array('staff_id'), + 'ref_index_list' => ['staff_id'], 'on_update' => 'CASCADE', - ), - ), - ), - array( + ], + ], + ], + [ 'CREATE TABLE `actor` ( `actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `first_name` varchar(45) NOT NULL, @@ -80,9 +81,9 @@ class TableTest extends TestCase PRIMARY KEY (`actor_id`), KEY `idx_actor_last_name` (`last_name`) ) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8', - array(), - ), - array( + [], + ], + [ 'CREATE TABLE `address` ( `address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `address` varchar(50) NOT NULL, @@ -96,24 +97,24 @@ class TableTest extends TestCase KEY `idx_fk_city_id` (`city_id`), CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8', - array( - array( + [ + [ 'constraint' => 'fk_address_city', - 'index_list' => array('city_id'), + 'index_list' => ['city_id'], 'ref_db_name' => null, 'ref_table_name' => 'city', - 'ref_index_list' => array('city_id'), + 'ref_index_list' => ['city_id'], 'on_update' => 'CASCADE', - ), - ), - ) - ); + ], + ], + ], + ]; } /** - * @dataProvider getFieldsProvider - * * @param mixed $query + * + * @dataProvider getFieldsProvider */ public function testGetFields($query, array $expected) { @@ -123,12 +124,12 @@ class TableTest extends TestCase public function getFieldsProvider() { - return array( - array( + return [ + [ 'CREATE USER test', - array(), - ), - array( + [], + ], + [ 'CREATE TABLE `address` ( `address_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT, `address` varchar(50) NOT NULL, @@ -142,76 +143,76 @@ class TableTest extends TestCase KEY `idx_fk_city_id` (`city_id`), CONSTRAINT `fk_address_city` FOREIGN KEY (`city_id`) REFERENCES `city` (`city_id`) ON UPDATE CASCADE ) ENGINE=InnoDB AUTO_INCREMENT=606 DEFAULT CHARSET=utf8', - array( - 'address_id' => array( + [ + 'address_id' => [ 'type' => 'SMALLINT', 'timestamp_not_null' => false, - ), - 'address' => array( + ], + 'address' => [ 'type' => 'VARCHAR', 'timestamp_not_null' => false, - ), - 'address2' => array( + ], + 'address2' => [ 'type' => 'VARCHAR', 'timestamp_not_null' => false, 'default_value' => 'NULL', - ), - 'district' => array( + ], + 'district' => [ 'type' => 'VARCHAR', 'timestamp_not_null' => false, - ), - 'city_id' => array( + ], + 'city_id' => [ 'type' => 'SMALLINT', 'timestamp_not_null' => false, - ), - 'postal_code' => array( + ], + 'postal_code' => [ 'type' => 'VARCHAR', 'timestamp_not_null' => false, 'default_value' => 'NULL', - ), - 'phone' => array( + ], + 'phone' => [ 'type' => 'VARCHAR', 'timestamp_not_null' => false, - ), - 'last_update' => array( + ], + 'last_update' => [ 'type' => 'TIMESTAMP', 'timestamp_not_null' => true, 'default_value' => 'CURRENT_TIMESTAMP', 'default_current_timestamp' => true, 'on_update_current_timestamp' => true, - ), - ), - ), - array( + ], + ], + ], + [ 'CREATE TABLE table1 ( a INT NOT NULL, b VARCHAR(32), c INT AS (a mod 10) VIRTUAL, d VARCHAR(5) AS (left(b,5)) PERSISTENT )', - array( - 'a' => array( + [ + 'a' => [ 'type' => 'INT', 'timestamp_not_null' => false, - ), - 'b' => array( + ], + 'b' => [ 'type' => 'VARCHAR', 'timestamp_not_null' => false, - ), - 'c' => array( + ], + 'c' => [ 'type' => 'INT', 'timestamp_not_null' => false, 'generated' => true, 'expr' => '(a mod 10)', - ), - 'd' => array( + ], + 'd' => [ 'type' => 'VARCHAR', 'timestamp_not_null' => false, 'generated' => true, 'expr' => '(left(b,5))', - ), - ), - ) - ); + ], + ], + ], + ]; } } diff --git a/tests/Utils/TokensTest.php b/tests/Utils/TokensTest.php index 685c670..b71a873 100644 --- a/tests/Utils/TokensTest.php +++ b/tests/Utils/TokensTest.php @@ -1,4 +1,5 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tests\Utils; @@ -9,12 +10,12 @@ use PhpMyAdmin\SqlParser\Utils\Tokens; class TokensTest extends TestCase { /** - * @dataProvider replaceTokensProvider - * * @param mixed $list * @param mixed $find * @param mixed $replace * @param mixed $expected + * + * @dataProvider replaceTokensProvider */ public function testReplaceTokens($list, $find, $replace, $expected) { @@ -23,28 +24,28 @@ class TokensTest extends TestCase public function replaceTokensProvider() { - return array( - array( + return [ + [ 'SELECT * FROM /*x*/a/*c*/.b', - array( - array('value_str' => 'a'), - array('token' => '.'), - ), - array( + [ + ['value_str' => 'a'], + ['token' => '.'], + ], + [ new Token('c'), new Token('.'), - ), + ], 'SELECT * FROM /*x*/c.b', - ) - ); + ], + ]; } /** - * @dataProvider matchProvider - * * @param mixed $token * @param mixed $pattern * @param mixed $expected + * + * @dataProvider matchProvider */ public function testMatch($token, $pattern, $expected) { @@ -53,64 +54,64 @@ class TokensTest extends TestCase public function matchProvider() { - return array( - array( + return [ + [ new Token(''), - array(), + [], true, - ), + ], - array( + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('token' => '"abc"'), + ['token' => '"abc"'], true, - ), - array( + ], + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('value' => 'abc'), + ['value' => 'abc'], true, - ), - array( + ], + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('value_str' => 'ABC'), + ['value_str' => 'ABC'], true, - ), - array( + ], + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('type' => Token::TYPE_STRING), + ['type' => Token::TYPE_STRING], true, - ), - array( + ], + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('flags' => Token::FLAG_STRING_DOUBLE_QUOTES), + ['flags' => Token::FLAG_STRING_DOUBLE_QUOTES], true, - ), + ], - array( + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('token' => '"abcd"'), + ['token' => '"abcd"'], false, - ), - array( + ], + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('value' => 'abcd'), + ['value' => 'abcd'], false, - ), - array( + ], + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('value_str' => 'ABCd'), + ['value_str' => 'ABCd'], false, - ), - array( + ], + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('type' => Token::TYPE_NUMBER), + ['type' => Token::TYPE_NUMBER], false, - ), - array( + ], + [ new Token('"abc"', Token::TYPE_STRING, Token::FLAG_STRING_DOUBLE_QUOTES), - array('flags' => Token::FLAG_STRING_SINGLE_QUOTES), + ['flags' => Token::FLAG_STRING_SINGLE_QUOTES], false, - ) - ); + ], + ]; } } diff --git a/tools/ContextGenerator.php b/tools/ContextGenerator.php index d4c5407..ba424ab 100644 --- a/tools/ContextGenerator.php +++ b/tools/ContextGenerator.php @@ -1,15 +1,14 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tools; +use Exception; + require_once __DIR__ . '/../vendor/autoload.php'; /** * Used for context generation. - * - * @category Contexts - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class ContextGenerator { @@ -18,19 +17,19 @@ class ContextGenerator * * @var array */ - public static $LABELS_FLAGS = array( + public static $LABELS_FLAGS = [ '(R)' => 2, // reserved '(D)' => 8, // data type '(K)' => 16, // keyword - '(F)' => 32 // function name - ); + '(F)' => 32, // function name + ]; /** * Documentation links for each context. * * @var array */ - public static $LINKS = array( + public static $LINKS = [ 'MySql50000' => 'https://dev.mysql.com/doc/refman/5.0/en/keywords.html', 'MySql50100' => 'https://dev.mysql.com/doc/refman/5.1/en/keywords.html', 'MySql50500' => 'https://dev.mysql.com/doc/refman/5.5/en/keywords.html', @@ -40,8 +39,8 @@ class ContextGenerator 'MariaDb100000' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/', 'MariaDb100100' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/', 'MariaDb100200' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/', - 'MariaDb100300' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/' - ); + 'MariaDb100300' => 'https://mariadb.com/kb/en/the-mariadb-library/reserved-words/', + ]; /** * The template of a context. @@ -56,7 +55,6 @@ class ContextGenerator */ const TEMPLATE = '<?php' . "\n" . - '' . "\n" . '/**' . "\n" . ' * Context for %1$s.' . "\n" . ' *' . "\n" . @@ -64,6 +62,7 @@ class ContextGenerator ' *' . "\n" . ' * @see %3$s' . "\n" . ' */' . "\n" . + 'declare(strict_types=1);' . "\n" . '' . "\n" . 'namespace PhpMyAdmin\\SqlParser\\Contexts;' . "\n" . '' . "\n" . @@ -90,9 +89,9 @@ class ContextGenerator ' *' . "\n" . ' * @var array' . "\n" . ' */' . "\n" . - ' public static $KEYWORDS = array(' . "\n" . + ' public static $KEYWORDS = [' . "\n" . '%4$s' . - ' );' . "\n" . + ' ];' . "\n" . '}' . "\n"; /** @@ -124,12 +123,12 @@ class ContextGenerator */ public static function readWords(array $files) { - $words = array(); + $words = []; foreach ($files as $file) { $words = array_merge($words, file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES)); } - $types = array(); + $types = []; for ($i = 0, $count = count($words); $i !== $count; ++$i) { $type = 1; @@ -162,14 +161,14 @@ class ContextGenerator } } - $ret = array(); + $ret = []; foreach ($types as $word => $type) { $len = strlen($word); if (! isset($ret[$type])) { - $ret[$type] = array(); + $ret[$type] = []; } if (! isset($ret[$type][$len])) { - $ret[$type][$len] = array(); + $ret[$type][$len] = []; } $ret[$type][$len][] = $word; } @@ -254,7 +253,7 @@ class ContextGenerator public static function formatName($name) { /* Split name and version */ - $parts = array(); + $parts = []; if (preg_match('/([^[0-9]*)([0-9]*)/', $name, $parts) === false) { return $name; } @@ -334,18 +333,18 @@ class ContextGenerator file_put_contents( $output . '/' . $class . '.php', static::generate( - array( + [ 'name' => $formattedName, 'class' => $class, 'link' => static::$LINKS[$name], 'keywords' => static::readWords( - array( + [ $directory . '_common.txt', $directory . '_functions' . $file, - $directory . $file - ) - ) - ) + $directory . $file, + ] + ), + ] ) ); } @@ -381,7 +380,6 @@ class ContextGenerator // // Input data must be in the `data` folder. // The output will be generated in the same `data` folder. -// if (count($argv) >= 3) { // Extracting directories' name from command line and trimming unnecessary // slashes at the end. @@ -390,9 +388,9 @@ if (count($argv) >= 3) { // Checking if all directories are valid. if (! is_dir($input)) { - throw new \Exception('The input directory does not exist.'); + throw new Exception('The input directory does not exist.'); } elseif (! is_dir($output)) { - throw new \Exception('The output directory does not exist.'); + throw new Exception('The output directory does not exist.'); } // Finally, building the tests. diff --git a/tools/TestGenerator.php b/tools/TestGenerator.php index 5f59f01..c5838b8 100644 --- a/tools/TestGenerator.php +++ b/tools/TestGenerator.php @@ -1,18 +1,16 @@ <?php +declare(strict_types=1); namespace PhpMyAdmin\SqlParser\Tools; require_once '../vendor/autoload.php'; +use Exception; use PhpMyAdmin\SqlParser\Lexer; use PhpMyAdmin\SqlParser\Parser; /** * Used for test generation. - * - * @category Tests - * - * @license https://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ */ class TestGenerator { @@ -39,21 +37,21 @@ class TestGenerator * * @var Parser */ - $parser = ($type === 'parser') ? new Parser($lexer->list) : null; + $parser = $type === 'parser' ? new Parser($lexer->list) : null; /** * Lexer's errors. * * @var array */ - $lexerErrors = array(); + $lexerErrors = []; /** * Parser's errors. * * @var array */ - $parserErrors = array(); + $parserErrors = []; // Both the lexer and the parser construct exception for errors. // Usually, exceptions contain a full stack trace and other details that @@ -63,37 +61,37 @@ class TestGenerator // Extracting lexer's errors. if (! empty($lexer->errors)) { foreach ($lexer->errors as $err) { - $lexerErrors[] = array( + $lexerErrors[] = [ $err->getMessage(), $err->ch, $err->pos, - $err->getCode() - ); + $err->getCode(), + ]; } - $lexer->errors = array(); + $lexer->errors = []; } // Extracting parser's errors. if (! empty($parser->errors)) { foreach ($parser->errors as $err) { - $parserErrors[] = array( + $parserErrors[] = [ $err->getMessage(), $err->token, - $err->getCode() - ); + $err->getCode(), + ]; } - $parser->errors = array(); + $parser->errors = []; } - return array( + return [ 'query' => $query, 'lexer' => $lexer, 'parser' => $parser, - 'errors' => array( + 'errors' => [ 'lexer' => $lexerErrors, 'parser' => $parserErrors, - ) - ); + ], + ]; } /** @@ -109,8 +107,8 @@ class TestGenerator public static function build($type, $input, $output, $debug = null) { // Support query types: `lexer` / `parser`. - if (! in_array($type, array('lexer', 'parser'))) { - throw new \Exception('Unknown test type (expected `lexer` or `parser`).'); + if (! in_array($type, ['lexer', 'parser'])) { + throw new Exception('Unknown test type (expected `lexer` or `parser`).'); } /** @@ -122,7 +120,7 @@ class TestGenerator // There is no point in generating a test without a query. if (empty($query)) { - throw new \Exception('No input query specified.'); + throw new Exception('No input query specified.'); } $test = static::generate($query, $type); @@ -156,7 +154,7 @@ class TestGenerator // Appending the filename to directories. $inputFile = $input . '/' . $file; $outputFile = $output . '/' . $file; - $debugFile = ($debug !== null) ? $debug . '/' . $file : null; + $debugFile = $debug !== null ? $debug . '/' . $file : null; if (is_dir($inputFile)) { // Creating required directories to maintain the structure. @@ -203,7 +201,6 @@ class TestGenerator // // Input data must be in the `../tests/data` folder. // The output will be generated in the same `../tests/data` folder. -// if (count($argv) >= 3) { // Extracting directories' name from command line and trimming unnecessary // slashes at the end. @@ -213,11 +210,11 @@ if (count($argv) >= 3) { // Checking if all directories are valid. if (! is_dir($input)) { - throw new \Exception('The input directory does not exist.'); + throw new Exception('The input directory does not exist.'); } elseif (! is_dir($output)) { - throw new \Exception('The output directory does not exist.'); + throw new Exception('The output directory does not exist.'); } elseif (($debug !== null) && (! is_dir($debug))) { - throw new \Exception('The debug directory does not exist.'); + throw new Exception('The debug directory does not exist.'); } // Finally, building the tests. diff --git a/tools/sami-config.php b/tools/sami-config.php index 39db4ed..f8dad47 100644 --- a/tools/sami-config.php +++ b/tools/sami-config.php @@ -14,9 +14,9 @@ $iterator = Finder::create() ->in("./src") ; -return new Sami($iterator, array( +return new Sami($iterator, [ "title" => "A validating SQL lexer and parser with a focus on MySQL dialect.", "build_dir" => "./doc/", "cache_dir" => "./tmp" -)); +]); |