From 92d511589ead4d6fb6c09e8d440585eefae9528a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 23 Aug 2024 10:41:16 +0700 Subject: [PATCH] Minor refactoring --- CHANGELOG.md | 2 +- rector.php | 9 ++++++++- src/DQLQueryBuilder.php | 5 +++-- src/Schema.php | 18 ++++++++---------- tests/Provider/ColumnSchemaBuilderProvider.php | 10 ++++------ tests/Provider/QueryBuilderProvider.php | 5 +++-- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f72e647..517db4d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +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) -- Chg #315: Raise minimum PHP version to `^8.1` (@Tigrov) +- Enh #315: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov) ## 1.2.0 March 21, 2024 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