From f0acbe53160fe5dd32cf9a535f83e5fb4818c150 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sat, 3 Feb 2024 20:25:26 +0700 Subject: [PATCH] Fix psalm issues (#288) Co-authored-by: Sergei Predvoditelev --- .github/workflows/static.yml | 6 ++++++ CHANGELOG.md | 1 + composer.json | 2 +- psalm.xml | 1 + psalm4.xml | 19 +++++++++++++++++++ src/DDLQueryBuilder.php | 4 ++-- src/Schema.php | 2 +- 7 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 psalm4.xml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0b170765..b7778798 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -39,6 +39,7 @@ jobs: - '8.0' - '8.1' - '8.2' + - '8.3' steps: - name: Checkout. @@ -70,4 +71,9 @@ jobs: run: composer update --no-interaction --no-progress --optimize-autoloader --ansi - name: Static analysis. + if: ${{ matrix.php != '8.0' }} run: vendor/bin/psalm --config=${{ inputs.psalm-config }} --shepherd --stats --output-format=github --php-version=${{ matrix.php }} + + - name: Static analysis. + if: ${{ matrix.php == '8.0' }} + run: vendor/bin/psalm --config=psalm4.xml --shepherd --stats --output-format=github --php-version=${{ matrix.php }} diff --git a/CHANGELOG.md b/CHANGELOG.md index b78d56f3..3dc7d3b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Enh #281: Remove unused code in `Command` class (@vjik) - Enh #282: Change property `Schema::$typeMap` to constant `Schema::TYPE_MAP` (@Tigrov) - Enh #283: Remove unnecessary check for array type in `Schema::loadTableIndexes()` (@Tigrov) +- Enh #288: Minor refactoring of `DDLQueryBuilder` and `Schema` (@Tigrov) ## 1.1.0 November 12, 2023 diff --git a/composer.json b/composer.json index c2223a5a..5e57c922 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "rector/rector": "^0.19", "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", - "vimeo/psalm": "^4.3|^5.6", + "vimeo/psalm": "^4.30|^5.20", "yiisoft/aliases": "^2.0", "yiisoft/cache-file": "^3.1", "yiisoft/json": "^1.0", diff --git a/psalm.xml b/psalm.xml index 10d319ae..906206a6 100644 --- a/psalm.xml +++ b/psalm.xml @@ -15,5 +15,6 @@ + diff --git a/psalm4.xml b/psalm4.xml new file mode 100644 index 00000000..10d319ae --- /dev/null +++ b/psalm4.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + diff --git a/src/DDLQueryBuilder.php b/src/DDLQueryBuilder.php index 84a9c89b..15b8cd92 100644 --- a/src/DDLQueryBuilder.php +++ b/src/DDLQueryBuilder.php @@ -105,8 +105,8 @@ public function createIndex( [$schema, $table] = $tableParts; } - return 'CREATE ' . ($indexType ? ($indexType . ' ') : '') . 'INDEX ' - . $this->quoter->quoteTableName(($schema ? $schema . '.' : '') . $name) + return 'CREATE ' . (!empty($indexType) ? $indexType . ' ' : '') . 'INDEX ' + . $this->quoter->quoteTableName((!empty($schema) ? $schema . '.' : '') . $name) . ' ON ' . $this->quoter->quoteTableName($table) . ' (' . $this->queryBuilder->buildColumns($columns) . ')'; diff --git a/src/Schema.php b/src/Schema.php index 23d46723..3d2853c1 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -752,7 +752,7 @@ private function getJsonColumns(TableSchemaInterface $table): array $regexp = '/\bjson_valid\(\s*["`\[]?(.+?)["`\]]?\s*\)/i'; foreach ($checks as $check) { - if (preg_match_all($regexp, $check->getExpression(), $matches, PREG_SET_ORDER)) { + if (preg_match_all($regexp, $check->getExpression(), $matches, PREG_SET_ORDER) > 0) { foreach ($matches as $match) { $result[] = $match[1]; }