From 339f61895f0f8cda8795041d5e102c0dac0185d7 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Wed, 27 Mar 2024 21:37:47 +0100 Subject: [PATCH 1/2] Run phpcbf --- .../ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php | 6 +----- .../MongoDB/Aggregation/Stage/SetWindowFields/Output.php | 5 +---- lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | 2 +- lib/Doctrine/ODM/MongoDB/UnitOfWork.php | 8 ++++---- .../MongoDB/Tests/Functional/DocumentPersisterTest.php | 1 - .../MongoDB/Tests/Persisters/PersistenceBuilderTest.php | 2 -- tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php | 2 -- 7 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php index 026b850cc0..5237a194dd 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php @@ -102,11 +102,7 @@ public function getOperatorParams(): object return $this->appendScore($params); } - /** - * @param array|Geometry $geometry - * - * @return array - */ + /** @param array|Geometry $geometry */ private function convertGeometry($geometry): array { if (! $geometry instanceof Geometry) { diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/SetWindowFields/Output.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/SetWindowFields/Output.php index d9f1a9a966..386d9ff30e 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/SetWindowFields/Output.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/SetWindowFields/Output.php @@ -37,10 +37,7 @@ class Output extends Operator implements WindowOperators private string $currentField = ''; - /** - * @var array - * @psalm-var array - */ + /** @psalm-var array */ private array $windows = []; public function __construct(Builder $builder, private SetWindowFields $setWindowFields) diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index cb0d0e08bb..acef17b628 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -1851,7 +1851,7 @@ public function getEmbeddedFieldsMappings(): array { return array_filter( $this->associationMappings, - static fn ($assoc) => ! empty($assoc['embedded']) + static fn ($assoc) => ! empty($assoc['embedded']), ); } diff --git a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php index b25ea58eb0..c80b9d9099 100644 --- a/lib/Doctrine/ODM/MongoDB/UnitOfWork.php +++ b/lib/Doctrine/ODM/MongoDB/UnitOfWork.php @@ -854,7 +854,7 @@ private function computeOrRecomputeChangeSet(ClassMetadata $class, object $docum // Look for changes in associations of the document $associationMappings = array_filter( $class->associationMappings, - static fn ($assoc) => empty($assoc['notSaved']) + static fn ($assoc) => empty($assoc['notSaved']), ); foreach ($associationMappings as $mapping) { @@ -2169,7 +2169,7 @@ private function cascadeRefresh(object $document, array &$visited): void $associationMappings = array_filter( $class->associationMappings, - static fn ($assoc) => $assoc['isCascadeRefresh'] + static fn ($assoc) => $assoc['isCascadeRefresh'], ); foreach ($associationMappings as $mapping) { @@ -2229,7 +2229,7 @@ private function cascadeMerge(object $document, object $managedCopy, array &$vis $associationMappings = array_filter( $class->associationMappings, - static fn ($assoc) => $assoc['isCascadeMerge'] + static fn ($assoc) => $assoc['isCascadeMerge'], ); foreach ($associationMappings as $assoc) { @@ -2261,7 +2261,7 @@ private function cascadePersist(object $document, array &$visited): void $associationMappings = array_filter( $class->associationMappings, - static fn ($assoc) => $assoc['isCascadePersist'] + static fn ($assoc) => $assoc['isCascadePersist'], ); foreach ($associationMappings as $fieldName => $mapping) { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php index 326446298f..6be4e71123 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php @@ -602,7 +602,6 @@ public function testPrepareQueryOrNewObjWithEmbeddedReferenceToTargetDocumentWit self::assertEquals($expected, $documentPersister->prepareQueryOrNewObj($value)); } - /** @return array */ public static function dataProviderTestWriteConcern(): array { return [ diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php index 5e3f393f5e..015a4c184a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Persisters/PersistenceBuilderTest.php @@ -220,8 +220,6 @@ public function testPrepareInsertData(object $document, array $expectedData): vo /** * Provides data for @see PersistenceBuilderTest::testPrepareInsertData() * Returns arrays of array(document => expected data) - * - * @return array */ public static function getDocumentsAndExpectedData(): array { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php index 9f15207a16..77252d76d4 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php @@ -593,8 +593,6 @@ public static function provideExcludeProjections(): array * Provide arguments for select() and exclude() tests. * * @param bool $include Whether the field should be included or excluded - * - * @return array */ private static function provideProjections(bool $include): array { From 18f982807fad76d6cc4e169eb7ad5bce7dd69907 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Wed, 27 Mar 2024 22:10:04 +0100 Subject: [PATCH 2/2] Fix psalm errors --- lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php | 2 +- phpstan-baseline.neon | 10 ++++++++++ psalm-baseline.xml | 12 +----------- .../Tests/Mapping/BasicInheritanceMappingTest.php | 13 ++++++++++++- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index acef17b628..874050d9b5 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -1845,7 +1845,7 @@ public function getFieldMapping(string $fieldName): array /** * Gets mappings of fields holding embedded document(s). * - * @psalm-return array + * @psalm-return array */ public function getEmbeddedFieldsMappings(): array { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f8d7c76aa6..0aafde288d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -925,6 +925,16 @@ parameters: count: 1 path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php + - + message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Mapping\\\\MappedSuperclassRelated1\\:\\:\\$id is unused\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php + + - + message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Mapping\\\\MappedSuperclassRelated1\\:\\:\\$name is unused\\.$#" + count: 1 + path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php + - message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Mapping\\\\TransientBaseClass\\:\\:\\$transient1 is unused\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index bc854ae734..fe37bade60 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + @@ -60,14 +60,9 @@ - associationMappings, - static fn ($assoc) => ! empty($assoc['embedded']) - )]]> - ]]> @@ -305,11 +300,6 @@ name])]]> - - - - - diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php index f4ea08679b..832a208feb 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/BasicInheritanceMappingTest.php @@ -8,7 +8,6 @@ use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactory; use Doctrine\ODM\MongoDB\Mapping\MappingException; use Doctrine\ODM\MongoDB\Tests\BaseTestCase; -use Doctrine\ODM\MongoDB\Tests\Functional\MappedSuperclassRelated1; use function serialize; use function unserialize; @@ -132,6 +131,18 @@ class MappedSuperclassBase private $transient; } +#[ODM\Document] +class MappedSuperclassRelated1 +{ + /** @var int|null */ + #[ODM\Id(strategy: 'none')] + private $id; + + /** @var string|null */ + #[ODM\Field(type: 'string')] + private $name; +} + #[ODM\Document] class DocumentSubClass2 extends MappedSuperclassBase {