From ff1068608d10b14acb06f4b868c74de73067b674 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Sat, 3 Feb 2024 20:27:11 +0700 Subject: [PATCH] Minor refactoring of `Command` and `Quoter` + Fix psalm issues (#292) Co-authored-by: Sergei Predvoditelev --- .github/workflows/static.yml | 9 ++++++--- CHANGELOG.md | 1 + composer.json | 2 +- psalm.xml | 3 +++ psalm4.xml | 17 +++++++++++++++++ src/Command.php | 2 +- src/Quoter.php | 2 +- 7 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 psalm4.xml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0b1707659..bba896424 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. @@ -66,8 +67,10 @@ jobs: FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} - - name: Install dependencies with composer. - 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 2e15aba88..b2b24f215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Enh #286: Change property `Schema::$typeMap` to constant `Schema::TYPE_MAP` (@Tigrov) - Bug #287: Fix `DMLQueryBuilder::insertWithReturningPks()` and `Command::insertWithReturningPks()` methods (@Tigrov) +- Enh #292: Minor refactoring of `Command` and `Quoter` (@Tigrov) ## 1.1.0 November 12, 2023 diff --git a/composer.json b/composer.json index 29561e3e5..90826a545 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,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/var-dumper": "^1.5" diff --git a/psalm.xml b/psalm.xml index 23bfcce17..5001d0a76 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,4 +14,7 @@ + + + diff --git a/psalm4.xml b/psalm4.xml new file mode 100644 index 000000000..23bfcce17 --- /dev/null +++ b/psalm4.xml @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/src/Command.php b/src/Command.php index 69e30f76d..c7c665b7b 100644 --- a/src/Command.php +++ b/src/Command.php @@ -15,7 +15,7 @@ final class Command extends AbstractPdoCommand public function insertWithReturningPks(string $table, array $columns): bool|array { if (empty($this->db->getSchema()->getTableSchema($table)?->getPrimaryKey())) { - if (parent::insert($table, $columns)->execute() === 0) { + if ($this->insert($table, $columns)->execute() === 0) { return false; } diff --git a/src/Quoter.php b/src/Quoter.php index 2a7fd735d..5ab8d06c8 100644 --- a/src/Quoter.php +++ b/src/Quoter.php @@ -25,7 +25,7 @@ public function quoteColumnName(string $name): string public function getTableNameParts(string $name, bool $withColumn = false): array { - if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches)) { + if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches) > 0) { $parts = array_slice($matches[0], -4, 4); } else { $parts = [$name];