From 334661b4cbc38def48d5487d351083a1ce779737 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 29 Jan 2024 12:56:25 +0700 Subject: [PATCH 1/8] Fix psalm issues --- src/DDLQueryBuilder.php | 4 ++-- src/Schema.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DDLQueryBuilder.php b/src/DDLQueryBuilder.php index 84a9c89b..c8f44fdf 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 ' . ($indexType !== null ? $indexType . ' ' : '') . 'INDEX ' + . $this->quoter->quoteTableName(($schema !== null ? $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]; } From e26cfd53d7689c9229e6a0386df20f1ef0c9f4d3 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 29 Jan 2024 21:12:21 +0700 Subject: [PATCH 2/8] Revert some changes and add suppression of `RiskyTruthyFalsyComparison` to config --- psalm.xml | 1 + src/DDLQueryBuilder.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) 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/src/DDLQueryBuilder.php b/src/DDLQueryBuilder.php index c8f44fdf..15b8cd92 100644 --- a/src/DDLQueryBuilder.php +++ b/src/DDLQueryBuilder.php @@ -105,8 +105,8 @@ public function createIndex( [$schema, $table] = $tableParts; } - return 'CREATE ' . ($indexType !== null ? $indexType . ' ' : '') . 'INDEX ' - . $this->quoter->quoteTableName(($schema !== null ? $schema . '.' : '') . $name) + return 'CREATE ' . (!empty($indexType) ? $indexType . ' ' : '') . 'INDEX ' + . $this->quoter->quoteTableName((!empty($schema) ? $schema . '.' : '') . $name) . ' ON ' . $this->quoter->quoteTableName($table) . ' (' . $this->queryBuilder->buildColumns($columns) . ')'; From 4d152691dfb092e6c18602fc391c22e257fefe64 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 30 Jan 2024 11:06:15 +0700 Subject: [PATCH 3/8] Run psalm on php 8.3 --- .github/workflows/static.yml | 4 +--- composer.json | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0b170765..92e84f9b 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -36,9 +36,7 @@ jobs: - ubuntu-latest php: - - '8.0' - - '8.1' - - '8.2' + - '8.3' steps: - name: Checkout. diff --git a/composer.json b/composer.json index c2223a5a..d27b8320 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": "^5.20", "yiisoft/aliases": "^2.0", "yiisoft/cache-file": "^3.1", "yiisoft/json": "^1.0", From b1b94bbebd37d319b1ba7b700fa574739100e2e4 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 30 Jan 2024 15:55:15 +0700 Subject: [PATCH 4/8] Change to `"vimeo/psalm": "^4.30|^5.20",`, add line to CHANGELOG.md --- CHANGELOG.md | 1 + composer.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b78d56f3..4c424325 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: Resolve psalm issues (@Tigrov) ## 1.1.0 November 12, 2023 diff --git a/composer.json b/composer.json index d27b8320..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": "^5.20", + "vimeo/psalm": "^4.30|^5.20", "yiisoft/aliases": "^2.0", "yiisoft/cache-file": "^3.1", "yiisoft/json": "^1.0", From 8643cf5e9392feb12be76e7ca196f5465ff96a3c Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 31 Jan 2024 10:38:29 +0700 Subject: [PATCH 5/8] Run psalm on PHP 8.0, 8.1, 8.2, 8.3 --- .github/workflows/static.yml | 8 ++++++++ psalm4.xml | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 psalm4.xml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 92e84f9b..b7778798 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -36,6 +36,9 @@ jobs: - ubuntu-latest php: + - '8.0' + - '8.1' + - '8.2' - '8.3' steps: @@ -68,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/psalm4.xml b/psalm4.xml new file mode 100644 index 00000000..10d319ae --- /dev/null +++ b/psalm4.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + From c827db8b9a984d3813801aae74a2a3961f06a2ae Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 1 Feb 2024 18:07:38 +0700 Subject: [PATCH 6/8] Fix test --- tests/SchemaTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index e15c3f1b..2a171127 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -352,11 +352,11 @@ public function testWorkWithPrimaryKeyConstraint(): void public function testNotConnectionPDO(): void { $db = $this->createMock(ConnectionInterface::class); - $schema = new Schema($db, DbHelper::getSchemaCache(), 'system'); + $schema = new Schema($db, DbHelper::getSchemaCache()); $this->expectException(NotSupportedException::class); $this->expectExceptionMessage('Only PDO connections are supported.'); - $schema->refreshTableSchema('customer'); + $schema->refresh(); } } From 84dc3dec4667bb6304c9d4a78ff6c0d61e6a6bbf Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 1 Feb 2024 18:08:01 +0700 Subject: [PATCH 7/8] Revert "Fix test" This reverts commit c827db8b9a984d3813801aae74a2a3961f06a2ae. --- tests/SchemaTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 2a171127..e15c3f1b 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -352,11 +352,11 @@ public function testWorkWithPrimaryKeyConstraint(): void public function testNotConnectionPDO(): void { $db = $this->createMock(ConnectionInterface::class); - $schema = new Schema($db, DbHelper::getSchemaCache()); + $schema = new Schema($db, DbHelper::getSchemaCache(), 'system'); $this->expectException(NotSupportedException::class); $this->expectExceptionMessage('Only PDO connections are supported.'); - $schema->refresh(); + $schema->refreshTableSchema('customer'); } } From 53a5b06c9fa2ac0df4c19019e08a6e08113f6dc2 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sat, 3 Feb 2024 10:18:17 +0700 Subject: [PATCH 8/8] Update CHANGELOG.md [skip ci] Co-authored-by: Sergei Predvoditelev --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c424325..3dc7d3b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +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: Resolve psalm issues (@Tigrov) +- Enh #288: Minor refactoring of `DDLQueryBuilder` and `Schema` (@Tigrov) ## 1.1.0 November 12, 2023