diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fddc974..acae62be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - Chg #308: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov) - Enh #312: Refactor `bit` type (@Tigrov) - Enh #315: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov) -- Chg #317: Raise minimum PHP version to `^8.1` (@Tigrov) +- Enh #317: 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 7e1860ee..1474cb20 100644 --- a/rector.php +++ b/rector.php @@ -4,8 +4,8 @@ use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; -use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; -use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; +use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Set\ValueObject\LevelSetList; return static function (RectorConfig $rectorConfig): void { @@ -22,11 +22,11 @@ // define sets of rules $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_80, + LevelSetList::UP_TO_PHP_81, ]); $rectorConfig->skip([ - ClosureToArrowFunctionRector::class, - JsonThrowOnErrorRector::class, + NullToStrictStringFuncCallArgRector::class, + ReadOnlyPropertyRector::class, ]); }; diff --git a/src/DQLQueryBuilder.php b/src/DQLQueryBuilder.php index 2dbeaa92..b01d5953 100644 --- a/src/DQLQueryBuilder.php +++ b/src/DQLQueryBuilder.php @@ -16,7 +16,6 @@ use Yiisoft\Db\QueryBuilder\Condition\InCondition; use Yiisoft\Db\QueryBuilder\Condition\LikeCondition; -use function array_merge; use function preg_match; /** @@ -47,11 +46,12 @@ public function selectExists(string $rawSql): string protected function defaultExpressionBuilders(): array { - return array_merge(parent::defaultExpressionBuilders(), [ + return [ + ...parent::defaultExpressionBuilders(), InCondition::class => InConditionBuilder::class, LikeCondition::class => LikeConditionBuilder::class, Expression::class => ExpressionBuilder::class, - ]); + ]; } /** diff --git a/src/Quoter.php b/src/Quoter.php index 33d76a24..0d50d1c6 100644 --- a/src/Quoter.php +++ b/src/Quoter.php @@ -30,7 +30,7 @@ public function getTableNameParts(string $name, bool $withColumn = false): array if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches) > 0) { $parts = array_slice($matches[0], -4, 4); - return array_map([$this, 'unquoteSimpleTableName'], $parts); + return array_map($this->unquoteSimpleTableName(...), $parts); } return [$this->unquoteSimpleTableName($name)]; diff --git a/src/Schema.php b/src/Schema.php index 226c7e74..c7cfc9d2 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -19,6 +19,7 @@ use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Schema\TableSchemaInterface; +use function array_change_key_case; use function array_map; use function explode; use function is_array; @@ -333,7 +334,7 @@ protected function loadTableIndexes(string $tableName): array $indexes = $this->db->createCommand($sql, [':fullName' => $resolvedName->getFullName()])->queryAll(); /** @psalm-var array[] $indexes */ - $indexes = array_map('array_change_key_case', $indexes); + $indexes = array_map(array_change_key_case(...), $indexes); $indexes = DbArrayHelper::index($indexes, null, ['name']); $result = []; @@ -840,7 +841,7 @@ private function loadTableConstraints(string $tableName, string $returnType): mi $constraints = $this->db->createCommand($sql, [':fullName' => $resolvedName->getFullName()])->queryAll(); /** @psalm-var array[] $constraints */ - $constraints = array_map('array_change_key_case', $constraints); + $constraints = array_map(array_change_key_case(...), $constraints); $constraints = DbArrayHelper::index($constraints, null, ['type', 'name']); $result = [ @@ -909,12 +910,10 @@ private function loadTableConstraints(string $tableName, string $returnType): mi * @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)]; } /** @@ -926,7 +925,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()])); } private function parseDefaultValue(string $value): string diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 58d2a9ee..3be139c2 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -155,7 +155,8 @@ function ($params) use ($expectedTableName) { public function withIndexDataProvider(): array { - return array_merge(parent::withIndexDataProvider(), [ + return [ + ...parent::withIndexDataProvider(), [ 'indexType' => SchemaInterface::INDEX_CLUSTERED, 'indexMethod' => null, @@ -166,7 +167,7 @@ public function withIndexDataProvider(): array 'indexMethod' => null, 'columnType' => 'varchar(16)', ], - ]); + ]; } public function testNotConnectionPDO(): void