Skip to content

Commit

Permalink
Remove $table parameter from normalizeColumnNames() (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored May 8, 2024
1 parent 7bb36b2 commit c702494
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
and change parameters from `$table, $columns, $rows` to `$table, $rows, $columns = []` (@Tigrov)
- Enh #834: Refactor `AbstractCommand::insertBatch()`, add `Quoter::getRawTableName()` to `QuoterInterface` (@Tigrov)
- Chg #836: Remove `AbstractDMLQueryBuilder::getTypecastValue()` method (@Tigrov)
- Chg #767: Remove `$table` parameter from `normalizeColumnNames()` and `getNormalizeColumnNames()` methods
of `AbstractDMLQueryBuilder` class (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ $db->createCommand()->insertBatch('user', $values)->execute();
### Remove deprecated methods

- `AbstractDMLQueryBuilder::getTypecastValue()`

### Remove deprecated parameters

- `$table` parameter from `AbstractDMLQueryBuilder::normalizeColumnNames()` method
- `$table` parameter from `AbstractDMLQueryBuilder::getNormalizeColumnNames()` method
16 changes: 7 additions & 9 deletions src/QueryBuilder/AbstractDMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected function prepareBatchInsertValues(string $table, iterable $rows, array
*/
protected function extractColumnNames(array|Iterator $rows, array $columns): array
{
$columns = $this->getNormalizeColumnNames('', $columns);
$columns = $this->getNormalizeColumnNames($columns);

if (!empty($columns)) {
return $columns;
Expand Down Expand Up @@ -332,7 +332,7 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu

$names = [];
$placeholders = [];
$columns = $this->normalizeColumnNames('', $columns);
$columns = $this->normalizeColumnNames($columns);
$columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? [];

foreach ($columns as $name => $value) {
Expand Down Expand Up @@ -366,7 +366,7 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu
protected function prepareUpdateSets(string $table, array $columns, array $params = []): array
{
$sets = [];
$columns = $this->normalizeColumnNames('', $columns);
$columns = $this->normalizeColumnNames($columns);
$columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? [];

foreach ($columns as $name => $value) {
Expand Down Expand Up @@ -410,7 +410,7 @@ protected function prepareUpsertColumns(
if ($insertColumns instanceof QueryInterface) {
[$insertNames] = $this->prepareInsertSelectSubQuery($insertColumns);
} else {
$insertNames = $this->getNormalizeColumnNames('', array_keys($insertColumns));
$insertNames = $this->getNormalizeColumnNames(array_keys($insertColumns));

$insertNames = array_map(
[$this->quoter, 'quoteColumnName'],
Expand Down Expand Up @@ -513,31 +513,29 @@ static function (Constraint $constraint) use ($quoter, $columns, &$columnNames):
/**
* Normalizes the column names.
*
* @param string $table Not used. Could be empty string. Will be removed in version 2.0.0.
* @param array $columns The column data (name => value).
*
* @return array The normalized column names (name => value).
*
* @psalm-return array<string, mixed>
*/
protected function normalizeColumnNames(string $table, array $columns): array
protected function normalizeColumnNames(array $columns): array
{
/** @var string[] $columnNames */
$columnNames = array_keys($columns);
$normalizedNames = $this->getNormalizeColumnNames('', $columnNames);
$normalizedNames = $this->getNormalizeColumnNames($columnNames);

return array_combine($normalizedNames, $columns);
}

/**
* Get normalized column names
*
* @param string $table Not used. Could be empty string. Will be removed in version 2.0.0.
* @param string[] $columns The column names.
*
* @return string[] Normalized column names.
*/
protected function getNormalizeColumnNames(string $table, array $columns): array
protected function getNormalizeColumnNames(array $columns): array
{
foreach ($columns as &$name) {
$name = $this->quoter->ensureColumnName($name);
Expand Down

0 comments on commit c702494

Please sign in to comment.