From 7250c1eaee4ed15a32a75762bd9d53b089416d4c Mon Sep 17 00:00:00 2001
From: Wilmer Arambula <42547589+terabytesoftw@users.noreply.github.com>
Date: Tue, 14 Feb 2023 14:10:04 -0300
Subject: [PATCH] Upgrade psalm-5.6. (#517)
---
composer.json | 2 +-
psalm.xml | 24 +++++++++++---------
src/Expression/ArrayExpression.php | 3 +++
src/Helper/ArrayHelper.php | 6 ++++-
src/Query/BatchQueryResultInterface.php | 2 ++
src/Query/Data/DataReaderInterface.php | 2 ++
src/QueryBuilder/AbstractDQLQueryBuilder.php | 2 ++
7 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/composer.json b/composer.json
index 0cbfae2e3..861ff8d77 100644
--- a/composer.json
+++ b/composer.json
@@ -33,7 +33,7 @@
"rector/rector": "^0.14",
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
- "vimeo/psalm": "^4.18",
+ "vimeo/psalm": "^4.30|^5.6",
"yiisoft/aliases": "^1.1|^2.0",
"yiisoft/cache-file": "^2.0",
"yiisoft/di": "^1.0",
diff --git a/psalm.xml b/psalm.xml
index 32408861d..23bfcce17 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -1,15 +1,17 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/src/Expression/ArrayExpression.php b/src/Expression/ArrayExpression.php
index aa24909e0..d91570819 100644
--- a/src/Expression/ArrayExpression.php
+++ b/src/Expression/ArrayExpression.php
@@ -25,6 +25,9 @@
*
* Which, depending on DBMS, will result in a well-prepared condition. For example, in PostgresSQL it will be compiled
* to `WHERE "items" @> ARRAY[1, 2, 3]::integer[]`.
+ *
+ * @template-implements ArrayAccess
+ * @template-implements IteratorAggregate
*/
class ArrayExpression implements ExpressionInterface, ArrayAccess, Countable, IteratorAggregate
{
diff --git a/src/Helper/ArrayHelper.php b/src/Helper/ArrayHelper.php
index 684962958..e1ff2a57a 100644
--- a/src/Helper/ArrayHelper.php
+++ b/src/Helper/ArrayHelper.php
@@ -205,10 +205,13 @@ public static function getValueByPath(object|array $array, Closure|string $key,
* @throws \Exception
*
* @return array the indexed and/or grouped array
+ *
+ * @psalm-suppress MixedArrayAssignment
*/
public static function index(array $array, string|null $key = null, array $groups = []): array
{
$result = [];
+
foreach ($array as $element) {
$lastArray = &$result;
@@ -229,12 +232,13 @@ public static function index(array $array, string|null $key = null, array $group
/** @psalm-var mixed $value */
$value = self::getValueByPath($element, $key);
if ($value !== null) {
- $lastArray[(string)$value] = $element;
+ $lastArray[(string) $value] = $element;
}
}
unset($lastArray);
}
+ /** @psalm-var array $result */
return $result;
}
diff --git a/src/Query/BatchQueryResultInterface.php b/src/Query/BatchQueryResultInterface.php
index dbd70eee0..ac58216ba 100644
--- a/src/Query/BatchQueryResultInterface.php
+++ b/src/Query/BatchQueryResultInterface.php
@@ -24,6 +24,8 @@
* foreach ($query->each() as $user) {
* }
* ```
+ *
+ * @extends Iterator
*/
interface BatchQueryResultInterface extends Iterator
{
diff --git a/src/Query/Data/DataReaderInterface.php b/src/Query/Data/DataReaderInterface.php
index d8ebaa24f..cfe2748eb 100644
--- a/src/Query/Data/DataReaderInterface.php
+++ b/src/Query/Data/DataReaderInterface.php
@@ -28,6 +28,8 @@
*
* Note that since DataReader is a forward-only stream, you can only traverse it once. Doing it the second time will
* throw an exception.
+ *
+ * @extends Iterator
*/
interface DataReaderInterface extends Iterator, Countable
{
diff --git a/src/QueryBuilder/AbstractDQLQueryBuilder.php b/src/QueryBuilder/AbstractDQLQueryBuilder.php
index 7fb783691..b84799668 100644
--- a/src/QueryBuilder/AbstractDQLQueryBuilder.php
+++ b/src/QueryBuilder/AbstractDQLQueryBuilder.php
@@ -219,6 +219,7 @@ public function buildGroupBy(array $columns, array &$params = []): string
}
}
+ /** @psalm-var array $columns */
return 'GROUP BY ' . implode(', ', $columns);
}
@@ -371,6 +372,7 @@ public function buildSelect(
}
}
+ /** @psalm-var array $columns */
return $select . ' ' . implode(', ', $columns);
}