Skip to content

Commit ca73e05

Browse files
committed
Apply rector on PHP 8.1 + minor refactoring
1 parent 36c4776 commit ca73e05

6 files changed

+22
-28
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
for type casting performance. Related with yiisoft/db#752 (@Tigrov)
1111
- Chg #272: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov)
1212
- Enh #275: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov)
13-
- Chg #277: Raise minimum PHP version to `^8.1` (@Tigrov)
13+
- Enh #277: Raise minimum PHP version to `^8.1` with minor refactoring (@Tigrov)
1414

1515
## 1.3.0 March 21, 2024
1616

rector.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
66
use Rector\Config\RectorConfig;
77
use Rector\Php73\Rector\String_\SensitiveHereNowDocRector;
8-
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
8+
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
9+
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
910
use Rector\Set\ValueObject\LevelSetList;
1011

1112
return static function (RectorConfig $rectorConfig): void {
@@ -22,11 +23,12 @@
2223

2324
// define sets of rules
2425
$rectorConfig->sets([
25-
LevelSetList::UP_TO_PHP_80,
26+
LevelSetList::UP_TO_PHP_81,
2627
]);
2728

2829
$rectorConfig->skip([
29-
ClosureToArrowFunctionRector::class,
30+
NullToStrictStringFuncCallArgRector::class,
31+
ReadOnlyPropertyRector::class,
3032
SensitiveHereNowDocRector::class,
3133
]);
3234
};

src/DMLQueryBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function insertBatch(string $table, iterable $rows, array $columns = [],
4040
$tableAndColumns = ' INTO ' . $this->quoter->quoteTableName($table);
4141

4242
if (count($columns) > 0) {
43-
$quotedColumnNames = array_map([$this->quoter, 'quoteColumnName'], $columns);
43+
$quotedColumnNames = array_map($this->quoter->quoteColumnName(...), $columns);
4444

4545
$tableAndColumns .= ' (' . implode(', ', $quotedColumnNames) . ')';
4646
}

src/DQLQueryBuilder.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Yiisoft\Db\QueryBuilder\Condition\InCondition;
1515
use Yiisoft\Db\QueryBuilder\Condition\LikeCondition;
1616

17-
use function array_merge;
1817
use function implode;
1918

2019
/**
@@ -84,13 +83,11 @@ public function buildWithQueries(array $withs, array &$params): string
8483

8584
protected function defaultExpressionBuilders(): array
8685
{
87-
return array_merge(
88-
parent::defaultExpressionBuilders(),
89-
[
90-
InCondition::class => InConditionBuilder::class,
91-
LikeCondition::class => LikeConditionBuilder::class,
92-
Expression::class => ExpressionBuilder::class,
93-
],
94-
);
86+
return [
87+
...parent::defaultExpressionBuilders(),
88+
InCondition::class => InConditionBuilder::class,
89+
LikeCondition::class => LikeConditionBuilder::class,
90+
Expression::class => ExpressionBuilder::class,
91+
];
9592
}
9693
}

src/Schema.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
use function array_change_key_case;
2626
use function array_map;
27-
use function array_merge;
2827
use function array_reverse;
2928
use function implode;
3029
use function is_array;
@@ -290,7 +289,7 @@ protected function loadTableIndexes(string $tableName): array
290289
])->queryAll();
291290

292291
/** @psalm-var array[] $indexes */
293-
$indexes = array_map('array_change_key_case', $indexes);
292+
$indexes = array_map(array_change_key_case(...), $indexes);
294293
$indexes = DbArrayHelper::index($indexes, null, ['name']);
295294

296295
$result = [];
@@ -605,7 +604,7 @@ protected function findConstraints(TableSchemaInterface $table): void
605604
}
606605

607606
foreach ($constraints as $index => $constraint) {
608-
$table->foreignKey($index, array_merge([$constraint['tableName']], $constraint['columns']));
607+
$table->foreignKey($index, [$constraint['tableName'], ...$constraint['columns']]);
609608
}
610609
}
611610

@@ -737,7 +736,7 @@ private function loadTableConstraints(string $tableName, string $returnType): mi
737736
])->queryAll();
738737

739738
/** @psalm-var array[] $constraints */
740-
$constraints = array_map('array_change_key_case', $constraints);
739+
$constraints = array_map(array_change_key_case(...), $constraints);
741740
$constraints = DbArrayHelper::index($constraints, null, ['type', 'name']);
742741

743742
$result = [
@@ -827,12 +826,10 @@ protected function findViewNames(string $schema = ''): array
827826
* @param string $name The table name.
828827
*
829828
* @return array The cache key.
830-
*
831-
* @psalm-suppress DeprecatedMethod
832829
*/
833830
protected function getCacheKey(string $name): array
834831
{
835-
return array_merge([self::class], $this->generateCacheKey(), [$this->db->getQuoter()->getRawTableName($name)]);
832+
return [self::class, ...$this->generateCacheKey(), $this->db->getQuoter()->getRawTableName($name)];
836833
}
837834

838835
/**
@@ -844,6 +841,6 @@ protected function getCacheKey(string $name): array
844841
*/
845842
protected function getCacheTag(): string
846843
{
847-
return md5(serialize(array_merge([self::class], $this->generateCacheKey())));
844+
return md5(serialize([self::class, ...$this->generateCacheKey()]));
848845
}
849846
}

tests/Provider/ColumnSchemaBuilderProvider.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ public static function types(): array
1717
$types[0][0] = 'integer UNSIGNED DEFAULT NULL NULL';
1818
$types[1][0] = 'integer(10) UNSIGNED';
1919

20-
return array_merge(
21-
$types,
22-
[
23-
['integer UNSIGNED', SchemaInterface::TYPE_INTEGER, null, [['unsigned']]],
24-
],
25-
);
20+
return [
21+
...$types,
22+
['integer UNSIGNED', SchemaInterface::TYPE_INTEGER, null, [['unsigned']]],
23+
];
2624
}
2725

2826
public static function createColumnTypes(): array

0 commit comments

Comments
 (0)