Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Aug 23, 2024
1 parent 85fb51a commit 92d5115
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
]);
};
5 changes: 3 additions & 2 deletions src/DQLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
];
}
}
18 changes: 8 additions & 10 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');

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

/**
Expand All @@ -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()]));
}

/**
Expand Down
10 changes: 4 additions & 6 deletions tests/Provider/ColumnSchemaBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 92d5115

Please sign in to comment.