From a490e0049dc21c59996d2d7154accf3145860f24 Mon Sep 17 00:00:00 2001 From: David Badura Date: Sat, 7 Nov 2026 12:03:46 +0100 Subject: [PATCH 1/2] Fix PHPStan errors after the PHPStan 2.2 update PHPStan 2.2 types variadic parameters as arrays that may have string keys, so the objects passed on to insertMany() and bulkWrite() no longer satisfied the list types and the baseline entries stopped matching. Normalizing the objects with array_values() also makes the $objects[0] access safe when a repository is called with named arguments. The mapping methods now declare that they throw UnknownPropertyPath, which PHPStan needs to accept a call whose result is unused in the tests. --- phpstan-baseline.neon | 24 ------------------------ src/Metadata/DocumentMetadata.php | 5 +++++ src/Repository/MongoDBRepository.php | 5 +++++ src/Repository/RangoRepository.php | 5 +++++ 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d71d325..2f9e3f0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -72,18 +72,6 @@ parameters: count: 1 path: src/Repository/MongoDBRepository.php - - - message: '#^Parameter \#1 \$documents of method MongoDB\\Collection\:\:insertMany\(\) expects list\, array\\> given\.$#' - identifier: argument.type - count: 1 - path: src/Repository/MongoDBRepository.php - - - - message: '#^Parameter \#1 \$operations of method MongoDB\\Collection\:\:bulkWrite\(\) expects list\, non\-empty\-array\, array\{''\$set''\: array\\}\}\}\> given\.$#' - identifier: argument.type - count: 1 - path: src/Repository/MongoDBRepository.php - - message: '#^Parameter \#2 \$data of method Patchlevel\\ODM\\Hydrator\\DocumentHydrator\:\:hydrate\(\) expects array\, array\|object given\.$#' identifier: argument.type @@ -114,18 +102,6 @@ parameters: count: 1 path: src/Repository/RangoRepository.php - - - message: '#^Parameter \#1 \$documents of method Patchlevel\\Rango\\Collection\\>\:\:insertMany\(\) expects list\\>, array\\> given\.$#' - identifier: argument.type - count: 1 - path: src/Repository/RangoRepository.php - - - - message: '#^Parameter \#1 \$operations of method Patchlevel\\Rango\\Collection\\>\:\:bulkWrite\(\) expects list\\>\>\>, non\-empty\-array\, array\{''\$set''\: array\\}\}\}\> given\.$#' - identifier: argument.type - count: 1 - path: src/Repository/RangoRepository.php - - message: '#^Property Patchlevel\\ODM\\Repository\\RangoRepository\:\:\$collection with generic class Patchlevel\\Rango\\Collection does not specify its types\: TDocument$#' identifier: missingType.generics diff --git a/src/Metadata/DocumentMetadata.php b/src/Metadata/DocumentMetadata.php index bef9ff8..03be4c5 100644 --- a/src/Metadata/DocumentMetadata.php +++ b/src/Metadata/DocumentMetadata.php @@ -122,6 +122,7 @@ public function discriminatorFilter(): array return [$this->discriminatorField => ['$in' => $this->discriminatorValues]]; } + /** @throws UnknownPropertyPath */ public function propertyPathToFieldPath(string $propertyPath): string { return $this->propertyPathToFieldPathWithChildren($propertyPath, $this->fields)[0]; @@ -131,6 +132,8 @@ public function propertyPathToFieldPath(string $propertyPath): string * @param array $filter * * @return array + * + * @throws UnknownPropertyPath */ public function mapFilterToFieldPaths(array $filter): array { @@ -210,6 +213,8 @@ private function propertyPathToFieldPathWithChildren(string $propertyPath, array * @param array $orderBy * * @return array + * + * @throws UnknownPropertyPath */ public function mapSortingToFieldPaths(array $orderBy): array { diff --git a/src/Repository/MongoDBRepository.php b/src/Repository/MongoDBRepository.php index 4c9b03e..f6bc0e4 100644 --- a/src/Repository/MongoDBRepository.php +++ b/src/Repository/MongoDBRepository.php @@ -12,6 +12,7 @@ use Patchlevel\ODM\Metadata\DocumentMetadata; use function array_map; +use function array_values; use function count; use function in_array; use function iterator_to_array; @@ -40,6 +41,8 @@ public function __construct( /** @param list ...$objects */ public function insert(object ...$objects): void { + $objects = array_values($objects); + try { if (count($objects) === 1) { $object = $objects[0]; @@ -73,6 +76,8 @@ public function update(object ...$objects): void return; } + $objects = array_values($objects); + if (count($objects) === 1) { $update = $this->prepareUpdate($objects[0]); diff --git a/src/Repository/RangoRepository.php b/src/Repository/RangoRepository.php index 233ef7d..79018b8 100644 --- a/src/Repository/RangoRepository.php +++ b/src/Repository/RangoRepository.php @@ -12,6 +12,7 @@ use Patchlevel\Rango\Exception\QueryException; use function array_map; +use function array_values; use function count; use function in_array; use function str_ends_with; @@ -39,6 +40,8 @@ public function __construct( /** @param list ...$objects */ public function insert(object ...$objects): void { + $objects = array_values($objects); + try { if (count($objects) === 1) { $object = $objects[0]; @@ -78,6 +81,8 @@ public function update(object ...$objects): void return; } + $objects = array_values($objects); + if (count($objects) === 1) { $update = $this->prepareUpdate($objects[0]); From 9aa2592a1c537aaa6549663ca3997755280992ad Mon Sep 17 00:00:00 2001 From: David Badura Date: Sat, 7 Nov 2026 12:03:46 +0100 Subject: [PATCH 2/2] Run the MongoDB integration tests against 6.0, 7.0 and 9.0 MongoDB 8.x refuses to start on the current GitHub runners because their kernel is 6.19 or newer (SERVER-121912). 9.0 starts fine. --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index b7fc8c0..1ea7fec 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -94,7 +94,7 @@ jobs: mongodb-version: - "6.0" - "7.0" - - "8.0" + - "9.0" env: MONGODB_URI: 'mongodb://localhost:27017'