Skip to content

Commit

Permalink
Update psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Oct 30, 2023
1 parent da705d2 commit 510afd1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<MixedAssignment errorLevel="suppress" />
</issueHandlers>
</psalm>
2 changes: 2 additions & 0 deletions src/Command/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ public function alterColumn(string $table, string $column, ColumnInterface|strin
* @throws Exception
* @throws InvalidArgumentException
*
* @psalm-param iterable<array-key, array<array-key, mixed>> $rows
*
* Note: The method will quote the `table` and `column` parameters before using them in the generated SQL.
*/
public function batchInsert(string $table, array $columns, iterable $rows): static;
Expand Down
21 changes: 5 additions & 16 deletions src/QueryBuilder/AbstractDMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ public function batchInsert(string $table, array $columns, iterable $rows, array
$columns = $this->getNormalizeColumnNames($columns);
$columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? [];

/** @psalm-var array[] $rows */
foreach ($rows as $row) {
$i = 0;
$placeholders = [];
/** @psalm-var mixed $value */

foreach ($row as $value) {
if (isset($columns[$i], $columnSchemas[$columns[$i]])) {
/** @psalm-var mixed $value */
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
}

Expand Down Expand Up @@ -213,15 +211,10 @@ protected function prepareInsertValues(string $table, array|QueryInterface $colu
$columns = $this->normalizeColumnNames($columns);
$columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? [];

/**
* @psalm-var mixed $value
* @psalm-var array<string, mixed> $columns
*/
foreach ($columns as $name => $value) {
$names[] = $this->quoter->quoteColumnName($name);

if (isset($columnSchemas[$name])) {
/** @var mixed $value */
$value = $columnSchemas[$name]->dbTypecast($value);
}

Expand Down Expand Up @@ -251,13 +244,8 @@ protected function prepareUpdateSets(string $table, array $columns, array $param
$columns = $this->normalizeColumnNames($columns);
$columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? [];

/**
* @psalm-var array<string, mixed> $columns
* @psalm-var mixed $value
*/
foreach ($columns as $name => $value) {
if (isset($columnSchemas[$name])) {
/** @psalm-var mixed $value */
$value = $columnSchemas[$name]->dbTypecast($value);
}

Expand All @@ -282,6 +270,7 @@ protected function prepareUpdateSets(string $table, array $columns, array $param
* @throws JsonException
* @throws NotSupportedException
*
* @psalm-param array<string, mixed>|QueryInterface $insertColumns
* @psalm-param Constraint[] $constraints
*
* @return array Array of unique, insert and update quoted column names.
Expand All @@ -296,7 +285,6 @@ protected function prepareUpsertColumns(
if ($insertColumns instanceof QueryInterface) {
[$insertNames] = $this->prepareInsertSelectSubQuery($insertColumns);
} else {
/** @psalm-var array<string, mixed> $insertColumns */
$insertNames = $this->getNormalizeColumnNames(array_keys($insertColumns));

$insertNames = array_map(
Expand All @@ -305,7 +293,6 @@ protected function prepareUpsertColumns(
);
}

/** @psalm-var string[] $uniqueNames */
$uniqueNames = $this->getTableUniqueColumnNames($table, $insertNames, $constraints);

if ($updateColumns === true) {
Expand All @@ -328,7 +315,7 @@ protected function prepareUpsertColumns(
*
* @throws JsonException
*
* @return array The quoted column names.
* @return string[] The quoted column names.
*
* @psalm-param Constraint[] $constraints
*/
Expand Down Expand Up @@ -405,6 +392,8 @@ static function (Constraint $constraint) use ($quoter, $columns, &$columnNames):
* @param array $columns The column data (name => value).
*
* @return array The normalized column names (name => value).
*
* @psalm-return array<string, mixed>
*/
protected function normalizeColumnNames(array $columns): array
{
Expand Down
1 change: 1 addition & 0 deletions src/QueryBuilder/DMLQueryBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface DMLQueryBuilderInterface
* @return string The batch INSERT SQL statement.
*
* @psalm-param string[] $columns
* @psalm-param iterable<array-key, array<array-key, mixed>> $rows
*
* Note:
* - That the values in each row must match the corresponding column names.
Expand Down

0 comments on commit 510afd1

Please sign in to comment.