From ab488208f54de9a42090de86da45a2184d01af08 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 23 Aug 2024 14:22:39 +0700 Subject: [PATCH] Raise PHP version to 8.1 (#315) --- .github/workflows/build.yml | 1 - .../workflows/composer-require-checker.yml | 1 - .github/workflows/static.yml | 6 ------ CHANGELOG.md | 1 + README.md | 6 +++--- composer.json | 6 +++--- psalm4.xml | 19 ------------------- rector.php | 9 ++++++++- src/DQLQueryBuilder.php | 5 +++-- src/Schema.php | 18 ++++++++---------- .../Provider/ColumnSchemaBuilderProvider.php | 10 ++++------ tests/Provider/QueryBuilderProvider.php | 5 +++-- 12 files changed, 33 insertions(+), 54 deletions(-) delete mode 100644 psalm4.xml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0031bab7..6bdd238b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,6 @@ jobs: - windows-latest php: - - 8.0 - 8.1 - 8.2 - 8.3 diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml index 58107cb7..c2ca43f8 100644 --- a/.github/workflows/composer-require-checker.yml +++ b/.github/workflows/composer-require-checker.yml @@ -29,7 +29,6 @@ jobs: - ubuntu-latest php: - - 8.0 - 8.1 - 8.2 - 8.3 diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 1660a1ad..95e5fd75 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -31,7 +31,6 @@ jobs: - ubuntu-latest php: - - '8.0' - '8.1' - '8.2' - '8.3' @@ -66,9 +65,4 @@ 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 966ae615..517db4d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Chg #307: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov) - Enh #310: Add JSON overlaps condition builder (@Tigrov) - Enh #312: Update `bit` type according to main PR yiisoft/db#860 (@Tigrov) +- Enh #315: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/README.md b/README.md index f81a1a79..8b1a83ec 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,9 @@ perform advanced database operations such as joins and aggregates. ## Support version -| PHP | Sqlite Version | CI-Actions | -|-----|---------------------------|------------| -|**8.0 - 8.2**| **3:latest**|[![build](https://github.com/yiisoft/db-sqlite/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-sqlite/actions/workflows/build.yml) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-sqlite%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-sqlite/master) [![static analysis](https://github.com/yiisoft/db-sqlite/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-sqlite/actions/workflows/static.yml) [![type-coverage](https://shepherd.dev/github/yiisoft/db-sqlite/coverage.svg)](https://shepherd.dev/github/yiisoft/db-sqlite) +| PHP | Sqlite Version | CI-Actions | +|---------------|---------------------------|------------| +| **8.1 - 8.3** | **3:latest**|[![build](https://github.com/yiisoft/db-sqlite/actions/workflows/build.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-sqlite/actions/workflows/build.yml) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fdb-sqlite%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/db-sqlite/master) [![static analysis](https://github.com/yiisoft/db-sqlite/actions/workflows/static.yml/badge.svg?branch=dev)](https://github.com/yiisoft/db-sqlite/actions/workflows/static.yml) [![type-coverage](https://shepherd.dev/github/yiisoft/db-sqlite/coverage.svg)](https://shepherd.dev/github/yiisoft/db-sqlite) ## Installation diff --git a/composer.json b/composer.json index 64509af2..8a4635ed 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "ext-mbstring": "*", "ext-pdo": "*", "yiisoft/db": "dev-master", @@ -40,11 +40,11 @@ "require-dev": { "ext-json": "*", "maglnet/composer-require-checker": "^4.2", - "phpunit/phpunit": "^9.6|^10.0", + "phpunit/phpunit": "^10.0", "rector/rector": "^1.1.1", "roave/infection-static-analysis-plugin": "^1.16", "spatie/phpunit-watcher": "^1.23", - "vimeo/psalm": "^4.30|^5.20", + "vimeo/psalm": "^5.25", "yiisoft/aliases": "^2.0", "yiisoft/cache-file": "^3.1", "yiisoft/json": "^1.0", diff --git a/psalm4.xml b/psalm4.xml deleted file mode 100644 index 10d319ae..00000000 --- a/psalm4.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - diff --git a/rector.php b/rector.php index 8cbdabbd..026867b3 100644 --- a/rector.php +++ b/rector.php @@ -4,6 +4,8 @@ use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; +use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { @@ -22,6 +24,11 @@ // define sets of rules $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_80, + LevelSetList::UP_TO_PHP_81, + ]); + + $rectorConfig->skip([ + NullToStrictStringFuncCallArgRector::class, + ReadOnlyPropertyRector::class, ]); }; diff --git a/src/DQLQueryBuilder.php b/src/DQLQueryBuilder.php index 2f4bed7c..3a29f362 100644 --- a/src/DQLQueryBuilder.php +++ b/src/DQLQueryBuilder.php @@ -136,12 +136,13 @@ public function buildUnion(array $unions, array &$params = []): string */ protected function defaultExpressionBuilders(): array { - return array_merge(parent::defaultExpressionBuilders(), [ + return [ + ...parent::defaultExpressionBuilders(), JsonOverlapsCondition::class => JsonOverlapsConditionBuilder::class, LikeCondition::class => LikeConditionBuilder::class, InCondition::class => InConditionBuilder::class, JsonExpression::class => JsonExpressionBuilder::class, Expression::class => ExpressionBuilder::class, - ]); + ]; } } diff --git a/src/Schema.php b/src/Schema.php index 9cf5dd9b..9fd5c674 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -20,9 +20,9 @@ use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; +use function array_change_key_case; use function array_column; use function array_map; -use function array_merge; use function count; use function explode; use function md5; @@ -205,7 +205,7 @@ protected function loadTableForeignKeys(string $tableName): array $foreignKeysList = $this->getPragmaForeignKeyList($tableName); /** @psalm-var ForeignKeyInfo[] $foreignKeysList */ - $foreignKeysList = array_map('array_change_key_case', $foreignKeysList); + $foreignKeysList = array_map(array_change_key_case(...), $foreignKeysList); $foreignKeysList = DbArrayHelper::index($foreignKeysList, null, ['table']); DbArrayHelper::multisort($foreignKeysList, 'seq'); @@ -409,7 +409,7 @@ protected function findConstraints(TableSchemaInterface $table): void $columnNames = (array) $foreignKey->getColumnNames(); $columnNames = array_combine($columnNames, $foreignKey->getForeignColumnNames()); - $foreignReference = array_merge([$foreignKey->getForeignTableName()], $columnNames); + $foreignReference = [$foreignKey->getForeignTableName(), ...$columnNames]; /** @psalm-suppress InvalidCast */ $table->foreignKey((string) $foreignKey->getName(), $foreignReference); @@ -563,7 +563,7 @@ private function loadTableColumnsInfo(string $tableName): array { $tableColumns = $this->getPragmaTableInfo($tableName); /** @psalm-var ColumnInfo[] $tableColumns */ - $tableColumns = array_map('array_change_key_case', $tableColumns); + $tableColumns = array_map(array_change_key_case(...), $tableColumns); /** @psalm-var ColumnInfo[] */ return DbArrayHelper::index($tableColumns, 'cid'); @@ -585,7 +585,7 @@ private function loadTableConstraints(string $tableName, string $returnType): Co { $indexList = $this->getPragmaIndexList($tableName); /** @psalm-var IndexListInfo[] $indexes */ - $indexes = array_map('array_change_key_case', $indexList); + $indexes = array_map(array_change_key_case(...), $indexList); $result = [ self::PRIMARY_KEY => null, self::INDEXES => [], @@ -663,7 +663,7 @@ private function getPragmaIndexInfo(string $name): array $column = $this->db ->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')') ->queryAll(); - $column = array_map('array_change_key_case', $column); + $column = array_map(array_change_key_case(...), $column); DbArrayHelper::multisort($column, 'seqno'); /** @psalm-var IndexInfo[] $column */ @@ -727,12 +727,10 @@ protected function findViewNames(string $schema = ''): array * @param string $name the table name. * * @return array The cache key. - * - * @psalm-suppress DeprecatedMethod */ protected function getCacheKey(string $name): array { - return array_merge([self::class], $this->generateCacheKey(), [$this->db->getQuoter()->getRawTableName($name)]); + return [self::class, ...$this->generateCacheKey(), $this->db->getQuoter()->getRawTableName($name)]; } /** @@ -744,7 +742,7 @@ protected function getCacheKey(string $name): array */ protected function getCacheTag(): string { - return md5(serialize(array_merge([self::class], $this->generateCacheKey()))); + return md5(serialize([self::class, ...$this->generateCacheKey()])); } /** diff --git a/tests/Provider/ColumnSchemaBuilderProvider.php b/tests/Provider/ColumnSchemaBuilderProvider.php index b39d6e24..cd05c57b 100644 --- a/tests/Provider/ColumnSchemaBuilderProvider.php +++ b/tests/Provider/ColumnSchemaBuilderProvider.php @@ -17,12 +17,10 @@ public static function types(): array $types[0][0] = 'integer UNSIGNED NULL DEFAULT NULL'; $types[1][0] = 'integer(10) UNSIGNED'; - return array_merge( - $types, - [ - ['integer UNSIGNED', SchemaInterface::TYPE_INTEGER, null, [['unsigned']]], - ], - ); + return [ + ...$types, + ['integer UNSIGNED', SchemaInterface::TYPE_INTEGER, null, [['unsigned']]], + ]; } public static function createColumnTypes(): array diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index f4d4e5d2..5934a913 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -30,7 +30,8 @@ public static function buildCondition(): array $buildCondition['inCondition-custom-6'], ); - return array_merge($buildCondition, [ + return [ + ...$buildCondition, 'composite in using array objects' => [ [ 'in', @@ -154,7 +155,7 @@ public static function buildCondition(): array ['=', new Expression("(json_col->>'$.someKey')"), 42], "(json_col->>'$.someKey') = :qp0", [':qp0' => 42], ], - ]); + ]; } public static function insert(): array