Skip to content

Commit

Permalink
Apply rector on PHP 8.1 + minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Aug 23, 2024
1 parent d00577a commit 9738f24
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
]);
};
6 changes: 3 additions & 3 deletions src/DQLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Yiisoft\Db\QueryBuilder\Condition\InCondition;
use Yiisoft\Db\QueryBuilder\Condition\LikeCondition;

use function array_merge;
use function preg_match;

/**
Expand Down Expand Up @@ -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,
]);
];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Quoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
11 changes: 5 additions & 6 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)];
}

/**
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -166,7 +167,7 @@ public function withIndexDataProvider(): array
'indexMethod' => null,
'columnType' => 'varchar(16)',
],
]);
];
}

public function testNotConnectionPDO(): void
Expand Down

0 comments on commit 9738f24

Please sign in to comment.