Skip to content

Commit bdb6552

Browse files
authored
Improve psalm types (#1087)
1 parent 847ad45 commit bdb6552

14 files changed

Lines changed: 22 additions & 28 deletions

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
- Enh #1065: Allow to use table name as a column prefix in update queries (@Tigrov)
161161
- Enh #1068: Quote string values as column names when join condition is an associative array (@Tigrov)
162162
- Chg #1070: Change "IndexBy" closure signature to `Closure(array|object):int|string` (@vjik)
163-
- Enh #1072, #1077, #1078, #1079, #1080, #1085: Improve psalm types (@vjik)
163+
- Enh #1072, #1077, #1078, #1079, #1080, #1085, #1087: Improve psalm types (@vjik)
164164
- New #1074: Add `ConnectionProvider` class (@Tigrov)
165165
- Chg #1075: Rename `Query::$join` property to `$joins` (@vjik)
166166
- New #1076: Allow to use expressions as table name or condition in "join" query methods (@vjik)

src/Cache/SchemaCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function invalidate(string $cacheTag): void
124124
return;
125125
}
126126

127-
/** @psalm-var string[] $data */
127+
/** @var string[] $data */
128128
$data = $this->psrCache->get($cacheTag, []);
129129

130130
foreach ($data as $key) {
@@ -224,7 +224,7 @@ private function addToTag(string $key, ?string $cacheTag = null): void
224224
return;
225225
}
226226

227-
/** @psalm-var string[] $data */
227+
/** @var string[] $data */
228228
$data = $this->psrCache->get($cacheTag, []);
229229
$data[] = $key;
230230
$this->psrCache->set($cacheTag, $data);

src/Command/AbstractCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,15 +413,15 @@ public function execute(): int
413413
return 0;
414414
}
415415

416-
/** @psalm-var int|bool $execute */
416+
/** @var bool|int $execute */
417417
$execute = $this->queryInternal(self::QUERY_MODE_EXECUTE);
418418

419419
return is_int($execute) ? $execute : 0;
420420
}
421421

422422
public function query(): DataReaderInterface
423423
{
424-
/** @psalm-var DataReaderInterface */
424+
/** @var DataReaderInterface */
425425
return $this->queryInternal(self::QUERY_MODE_CURSOR);
426426
}
427427

@@ -629,7 +629,6 @@ protected function queryInternal(int $queryMode): mixed
629629

630630
$this->internalExecute();
631631

632-
/** @psalm-var mixed $result */
633632
$result = $this->internalGetQueryResult($queryMode);
634633

635634
if (!$isReadMode) {

src/Command/CommandInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function addForeignKey(
140140
*
141141
* @param string $table The name of the table to add primary key constraint to.
142142
* @param string $name The name of the primary key constraint.
143-
* @param array|string $columns The comma separated string or array of columns that the primary key consists of.
143+
* @param string|string[] $columns The comma separated string or array of columns that the primary key consists of.
144144
*
145145
* Note: The method will quote the `name`, `table`, and `column` parameters before using them in the generated SQL.
146146
*/
@@ -237,7 +237,7 @@ public function bindParam(
237237
*
238238
* @param string $table The name of the table to add unique constraint to.
239239
* @param string $name The name of the unique constraint.
240-
* @param array|string $columns The name of the column to add unique constraint to. If there are
240+
* @param string|string[] $columns The name of the column to add unique constraint to. If there are
241241
* many columns, use an array or separate them with commas.
242242
*
243243
* Note: The method will quote the `name`, `table`, and `column` parameters before using them in the generated SQL.

src/Driver/Pdo/AbstractPdoCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,10 @@ protected function queryInternal(int $queryMode): mixed
295295

296296
$queryContext = new CommandContext(__METHOD__, $logCategory, $this->getSql(), $this->getParams());
297297

298-
/** @psalm-var string|null $rawSql */
298+
/** @var string|null $rawSql */
299299
$this->profiler?->begin($rawSql ??= $this->getRawSql(), $queryContext);
300-
/** @psalm-var string $rawSql */
300+
/** @var string $rawSql */
301301
try {
302-
/** @psalm-var mixed $result */
303302
$result = parent::queryInternal($queryMode);
304303
} catch (Throwable $e) {
305304
$this->profiler?->end($rawSql, $queryContext->setException($e));

src/Expression/ExpressionBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private function appendParams(array &$expressionParams, array &$params): array
8383
{
8484
$nonUniqueParams = [];
8585

86-
/** @var non-empty-string $name */
86+
/** @psalm-var non-empty-string $name */
8787
foreach ($expressionParams as $name => $value) {
8888
$paramName = $name[0] === ':' ? substr($name, 1) : $name;
8989

@@ -130,7 +130,7 @@ private function buildParamExpressions(array $expressionParams, array &$params):
130130
{
131131
$replacements = [];
132132

133-
/** @var non-empty-string $name */
133+
/** @psalm-var non-empty-string $name */
134134
foreach ($expressionParams as $name => $value) {
135135
if (!$value instanceof ExpressionInterface || $value instanceof Param) {
136136
continue;
@@ -164,7 +164,7 @@ private function mergeReplacements(array $replacements, array $expressionReplace
164164
return $replacements;
165165
}
166166

167-
/** @var non-empty-string $value */
167+
/** @psalm-var non-empty-string $value */
168168
foreach ($replacements as $name => $value) {
169169
if (isset($expressionReplacements[$value])) {
170170
$replacements[$name] = $expressionReplacements[$value];

src/Helper/DbArrayHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private static function indexArranged(
333333
Closure|null $resultCallback,
334334
int $depth,
335335
): void {
336-
/** @var list<array<string,mixed>> $rows */
336+
/** @psalm-var list<array<string,mixed>> $rows */
337337
foreach ($arranged as &$rows) {
338338
if ($depth > 1) {
339339
self::indexArranged($rows, $indexBy, $resultCallback, $depth - 1);

src/QueryBuilder/AbstractDDLQueryBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ public function addForeignKey(
104104
public function addPrimaryKey(string $table, string $name, array|string $columns): string
105105
{
106106
if (is_string($columns)) {
107+
/** @psalm-var list<string> */
107108
$columns = preg_split('/\s*,\s*/', $columns, -1, PREG_SPLIT_NO_EMPTY);
108109
}
109110

110-
/** @psalm-var string[] $columns */
111111
foreach ($columns as $i => $col) {
112112
$columns[$i] = $this->quoter->quoteColumnName($col);
113113
}
@@ -121,10 +121,10 @@ public function addPrimaryKey(string $table, string $name, array|string $columns
121121
public function addUnique(string $table, string $name, array|string $columns): string
122122
{
123123
if (is_string($columns)) {
124+
/** @psalm-var list<string> */
124125
$columns = preg_split('/\s*,\s*/', $columns, -1, PREG_SPLIT_NO_EMPTY);
125126
}
126127

127-
/** @psalm-var string[] $columns */
128128
foreach ($columns as $i => $col) {
129129
$columns[$i] = $this->quoter->quoteColumnName($col);
130130
}

src/QueryBuilder/AbstractDMLQueryBuilder.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ final protected function prepareTraversable(Traversable $rows): Iterator|array
238238
protected function prepareBatchInsertValues(string $table, iterable $rows, array $columnNames, array &$params): array
239239
{
240240
$values = [];
241-
/** @var string[] $names */
242241
$names = array_values($columnNames);
243242
$keys = array_fill_keys($names, false);
244243
$columns = $this->typecasting ? $this->schema->getTableSchema($table)?->getColumns() ?? [] : [];
@@ -327,7 +326,7 @@ protected function extractColumnNames(array|Iterator $rows, array $columns): arr
327326
*/
328327
protected function getQueryColumnNames(QueryInterface $query, array &$params = []): array
329328
{
330-
/** @psalm-var string[] $select */
329+
/** @var string[] $select */
331330
$select = $query->getSelect();
332331

333332
if (empty($select) || in_array('*', $select, true)) {
@@ -473,7 +472,7 @@ protected function prepareUpsertSets(
473472
$quoter = $this->quoter;
474473
$sets = [];
475474

476-
/** @psalm-var string[] $updateNames */
475+
/** @var string[] $updateNames */
477476
foreach ($updateNames as $name) {
478477
$quotedName = $quoter->quoteSimpleColumnName($name);
479478
$sets[] = "$quotedName=EXCLUDED.$quotedName";

src/QueryBuilder/AbstractDQLQueryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function buildFrom(array $tables, array &$params): string
216216
return '';
217217
}
218218

219-
/** @psalm-var string[] $tables */
219+
/** @var string[] $tables */
220220
$tables = $this->quoteTableNames($tables, $params);
221221

222222
return 'FROM ' . implode(', ', $tables);

0 commit comments

Comments
 (0)