diff --git a/composer.json b/composer.json index 5626992972..31fc855166 100644 --- a/composer.json +++ b/composer.json @@ -48,7 +48,7 @@ "phpunit/phpunit": "^8.5 || ^9", "squizlabs/php_codesniffer": "^3.5", "symfony/cache": "^4.4 || ^5.0 || ^6.0", - "vimeo/psalm": "^4.8.1" + "vimeo/psalm": "^4.20.0" }, "suggest": { "ext-bcmath": "Decimal128 type support" diff --git a/lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php b/lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php index 5bf52f2cd7..5a75d9201c 100644 --- a/lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php +++ b/lib/Doctrine/ODM/MongoDB/Iterator/PrimingIterator.php @@ -29,7 +29,7 @@ final class PrimingIterator implements Iterator /** @var ReferencePrimer */ private $referencePrimer; - /** @var array */ + /** @var array */ private $primers; /** @@ -42,9 +42,9 @@ final class PrimingIterator implements Iterator private $referencesPrimed = false; /** - * @param \Iterator $iterator - * @param ClassMetadata $class - * @param array $primers + * @param \Iterator $iterator + * @param ClassMetadata $class + * @param array $primers * @psalm-param Hints $unitOfWorkHints */ public function __construct(\Iterator $iterator, ClassMetadata $class, ReferencePrimer $referencePrimer, array $primers, array $unitOfWorkHints = []) diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeReader.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeReader.php index 1210253018..f8bf4fbcda 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeReader.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/AttributeReader.php @@ -20,16 +20,17 @@ */ final class AttributeReader implements Reader { - /** - * @param ReflectionClass $class - */ public function getClassAnnotations(ReflectionClass $class): array { return $this->convertToAttributeInstances($class->getAttributes()); } /** - * @param ReflectionClass $class + * @param class-string $annotationName + * + * @return T|null + * + * @template T */ public function getClassAnnotation(ReflectionClass $class, $annotationName) { @@ -47,6 +48,13 @@ public function getMethodAnnotations(ReflectionMethod $method): array return $this->convertToAttributeInstances($method->getAttributes()); } + /** + * @param class-string $annotationName + * + * @return T|null + * + * @template T + */ public function getMethodAnnotation(ReflectionMethod $method, $annotationName) { foreach ($this->getMethodAnnotations($method) as $annotation) { @@ -63,6 +71,13 @@ public function getPropertyAnnotations(ReflectionProperty $property): array return $this->convertToAttributeInstances($property->getAttributes()); } + /** + * @param class-string $annotationName + * + * @return T|null + * + * @template T + */ public function getPropertyAnnotation(ReflectionProperty $property, $annotationName) { foreach ($this->getPropertyAnnotations($property) as $annotation) { diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php index c46a3b695f..0df45fbeba 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php @@ -571,7 +571,7 @@ private function addIndex(ClassMetadata $class, SimpleXMLElement $xmlIndex): voi } /** - * @return array|scalar> + * @return array|scalar|null> */ private function getPartialFilterExpression(SimpleXMLElement $fields): array { diff --git a/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php b/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php index a6c0f17e29..62bf3f855a 100644 --- a/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php +++ b/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php @@ -428,6 +428,7 @@ public function isEmpty() /** * @return Traversable + * @psalm-return Traversable */ #[ReturnTypeWillChange] public function getIterator() @@ -540,6 +541,7 @@ public function offsetExists($offset) * @param mixed $offset * * @return mixed + * @psalm-return T|null */ #[ReturnTypeWillChange] public function offsetGet($offset) @@ -660,6 +662,11 @@ private function doAdd($value, $arrayAccess) * @param mixed $offset * * @return bool|T|null + * @psalm-return ( + * $arrayAccess is false + * ? T|null + * : T|null|true + * ) */ private function doRemove($offset, bool $arrayAccess) { diff --git a/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php b/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php index 5c4e9f242d..76225222dd 100644 --- a/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php @@ -70,8 +70,9 @@ public function generateProxyClasses(array $classes): int ->proxyFactory ->createProxy( $metadata->getName(), - static function () { + static function (): bool { // empty closure, serves its purpose, for now + return true; }, [ 'skippedProperties' => $this->skippedFieldsFqns($metadata), @@ -83,10 +84,18 @@ static function () { } /** - * @param ClassMetadata $metadata - * @param DocumentPersister $documentPersister + * @param ClassMetadata $metadata + * @param DocumentPersister $documentPersister * - * @template T of object + * @psalm-return Closure( + * TDocument&GhostObjectInterface, + * string, + * array, + * ?Closure=, + * array + * ) : bool + * + * @template TDocument of object */ private function createInitializer( ClassMetadata $metadata, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index df9765c975..5c662f9983 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -153,11 +153,6 @@ parameters: count: 1 path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM88Test.php - - - message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\\\:\\:mapField\\(\\)\\.$#" - count: 1 - path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php - - message: "#^Parameter \\#1 \\$primer of method Doctrine\\\\ODM\\\\MongoDB\\\\Query\\\\Builder\\:\\:prime\\(\\) expects bool\\|\\(callable\\(\\)\\: mixed\\), 1 given\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 0000000000..585f0c26c4 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,88 @@ + + + + + $this->num($limit) + + + self + + + + + [$this->identifier => $this->getIdentifierValue($object)] + + + + + $mapping + + + + + new PersistentCollection($coll, $dm, $dm->getUnitOfWork()) + + + + + $func + $p + $p + $p + $p + + + getMapping + + + getTypeClass + + + + + $className + + + + + $options + ['metadata' => (object) $metadata] + + + + + $this->identityMap + $this->originalDocumentData + + + $mapping['targetDocument'] + + + + + new ArrayCollection([$project]) + + + + + [$user->categories[0]->children, $user->categories[1]->children] + [$user->categories[0]->children[0]->children, $user->categories[0]->children[1]->children] + [$user->categories[0]->children[0]->children, $user->categories[0]->children[1]->children] + + + + + $i + $i + $j + $j + + + + + DocumentManager + + + $this->dm + + + diff --git a/psalm.xml b/psalm.xml index d2c79a1573..cf8ed9d09a 100644 --- a/psalm.xml +++ b/psalm.xml @@ -1,11 +1,12 @@ diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CommitImprovementTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CommitImprovementTest.php index de1a8099cb..4d331d5288 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/CommitImprovementTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/CommitImprovementTest.php @@ -101,17 +101,21 @@ public function testChangingCollectionInPostEventsHasNoIllEffects(): void $this->dm->persist($user); $this->dm->flush(); - $this->assertCount(1, $user->getPhonenumbers()); // so we got a number on postPersist - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getPhonenumbers()); // so we got a number on postPersist - $this->assertTrue($user->getPhonenumbers()->isDirty()); // but they should be dirty + $phoneNumbers = $user->getPhonenumbers(); + $this->assertCount(1, $phoneNumbers); // so we got a number on postPersist + $this->assertInstanceOf(PersistentCollectionInterface::class, $phoneNumbers); // so we got a number on postPersist + $this->assertTrue($phoneNumbers->isDirty()); // but they should be dirty $collection = $this->dm->getDocumentCollection(get_class($user)); $inDb = $collection->findOne(); $this->assertArrayNotHasKey('phonenumbers', $inDb, 'Collection modified in postPersist should not be in database without recomputing change set'); $this->dm->flush(); - $this->assertCount(2, $user->getPhonenumbers()); // so we got a number on postUpdate - $this->assertTrue($user->getPhonenumbers()->isDirty()); // but they should be dirty + + $phoneNumbers = $user->getPhonenumbers(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $phoneNumbers); + $this->assertCount(2, $phoneNumbers); // so we got a number on postUpdate + $this->assertTrue($phoneNumbers->isDirty()); // but they should be dirty $inDb = $collection->findOne(); $this->assertCount(1, $inDb['phonenumbers'], 'Collection changes from postUpdate should not be in database'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php index ad7d557dd7..c78f730f03 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/FilterTest.php @@ -10,12 +10,13 @@ use Documents\Group; use Documents\Profile; use Documents\User; +use MongoDB\BSON\ObjectId; use function sort; class FilterTest extends BaseTest { - /** @var array */ + /** @var array */ private $ids; /** @var FilterCollection */ diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/LifecycleTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/LifecycleTest.php index 3e1ad0397e..9aff1c2699 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/LifecycleTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/LifecycleTest.php @@ -79,7 +79,7 @@ class ParentObject /** * @ODM\EmbedOne(targetDocument=ChildEmbeddedObject::class) * - * @var ChildEmbeddedObject|null + * @var ChildEmbeddedObject */ private $childEmbedded; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php index 73d3c62b4b..2830af08e2 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReadPreferenceTest.php @@ -37,8 +37,9 @@ public function testHintIsNotSetByDefault(): void $user = $query->getSingleResult(); $this->assertInstanceOf(User::class, $user); - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getGroups()); - $this->assertArrayNotHasKey(Query::HINT_READ_PREFERENCE, $user->getGroups()->getHints()); + $groups = $user->getGroups(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $groups); + $this->assertArrayNotHasKey(Query::HINT_READ_PREFERENCE, $groups->getHints()); } /** @@ -58,8 +59,9 @@ public function testHintIsSetOnQuery(int $readPreference, array $tags = []): voi $user = $query->getSingleResult(); $this->assertInstanceOf(User::class, $user); - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getGroups()); - $this->assertReadPreferenceHint($readPreference, $user->getGroups()->getHints()[Query::HINT_READ_PREFERENCE], $tags); + $groups = $user->getGroups(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $groups); + $this->assertReadPreferenceHint($readPreference, $groups->getHints()[Query::HINT_READ_PREFERENCE], $tags); } public function provideReadPreferenceHints(): array diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php index 7e004b7fee..eddf6abe1e 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencesTest.php @@ -257,10 +257,11 @@ public function testFlushInitializesEmptyPersistentCollection(): void $this->dm->persist($user); $this->dm->flush(); - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getGroups()); - $this->assertTrue($user->getGroups()->isInitialized(), 'A flushed collection should be initialized'); - $this->assertCount(2, $user->getGroups()); - $this->assertCount(2, $user->getGroups()->toArray()); + $groups = $user->getGroups(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $groups); + $this->assertTrue($groups->isInitialized(), 'A flushed collection should be initialized'); + $this->assertCount(2, $groups); + $this->assertCount(2, $groups->toArray()); } public function testFlushInitializesNotEmptyPersistentCollection(): void @@ -280,10 +281,11 @@ public function testFlushInitializesNotEmptyPersistentCollection(): void $this->dm->persist($user); $this->dm->flush(); - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getGroups()); - $this->assertTrue($user->getGroups()->isInitialized(), 'A flushed collection should be initialized'); - $this->assertCount(3, $user->getGroups()); - $this->assertCount(3, $user->getGroups()->toArray()); + $groups = $user->getGroups(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $groups); + $this->assertTrue($groups->isInitialized(), 'A flushed collection should be initialized'); + $this->assertCount(3, $groups); + $this->assertCount(3, $groups->toArray()); } public function testManyReferenceWithAddToSetStrategy(): void diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1152Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1152Test.php index 9af05bdb86..8848c0419d 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1152Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1152Test.php @@ -58,11 +58,11 @@ class GH1152Parent /** * @ODM\EmbeddedDocument * - * @psalm-import-type FieldMapping from ClassMetadata + * @psalm-import-type AssociationFieldMapping from ClassMetadata */ class GH1152Child { - /** @psalm-var array{0: FieldMapping, 1: object|null, 2: string}|null */ + /** @psalm-var array{0: AssociationFieldMapping, 1: object|null, 2: string}|null */ public $parentAssociation; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1229Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1229Test.php index fb03db89e5..73b5269eb4 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1229Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1229Test.php @@ -203,7 +203,7 @@ class GH1229Child /** * @ODM\Field(type="int") * - * @var int|null + * @var int */ public $order = 0; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1775Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1775Test.php index d7f511c9b4..0f10a0cfc5 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1775Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1775Test.php @@ -38,6 +38,8 @@ public function testProxyInitializationDoesNotLoseData(): void $blog = $this->dm->find(GH1775Blog::class, $blogId); $image = $this->dm->find(GH1775Image::class, $imageId); + $this->assertInstanceOf(GH1775Blog::class, $blog); + $this->assertInstanceOf(GH1775Image::class, $image); $post2 = new GH1775Post([$blog], [$image]); $this->dm->persist($post2); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH499Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH499Test.php index 9d2fba19c9..0f98a9e73b 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH499Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH499Test.php @@ -42,7 +42,7 @@ class GH499Document /** * @ODM\Id * - * @var string|null + * @var string */ protected $id; diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH921Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH921Test.php index 22fef744b8..49b16e4f6f 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH921Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH921Test.php @@ -29,19 +29,21 @@ public function testPersistentCollectionCountAndIterationShouldBeConsistent(): v $this->dm->persist($postA); $this->dm->flush(); - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getPosts()); - $this->assertFalse($user->getPosts()->isDirty(), 'A flushed collection should not be dirty'); - $this->assertTrue($user->getPosts()->isInitialized(), 'A flushed collection should be initialized'); - $this->assertCount(1, $user->getPosts()); - $this->assertCount(1, $user->getPosts()->toArray()); + $posts = $user->getPosts(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $posts); + $this->assertFalse($posts->isDirty(), 'A flushed collection should not be dirty'); + $this->assertTrue($posts->isInitialized(), 'A flushed collection should be initialized'); + $this->assertCount(1, $posts); + $this->assertCount(1, $posts->toArray()); $this->dm->refresh($user); - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getPosts()); - $this->assertFalse($user->getPosts()->isDirty(), 'A refreshed collection should not be dirty'); - $this->assertFalse($user->getPosts()->isInitialized(), 'A refreshed collection should not be initialized'); - $this->assertCount(1, $user->getPosts()); - $this->assertCount(1, $user->getPosts()->toArray()); + $posts = $user->getPosts(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $posts); + $this->assertFalse($posts->isDirty(), 'A refreshed collection should not be dirty'); + $this->assertFalse($posts->isInitialized(), 'A refreshed collection should not be initialized'); + $this->assertCount(1, $posts); + $this->assertCount(1, $posts->toArray()); $this->dm->refresh($user); @@ -49,18 +51,18 @@ public function testPersistentCollectionCountAndIterationShouldBeConsistent(): v $user->addPost($postB); $this->dm->persist($postB); - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getPosts()); - $this->assertTrue($user->getPosts()->isDirty(), 'A refreshed collection then modified should be dirty'); - $this->assertFalse($user->getPosts()->isInitialized(), 'A refreshed collection then modified should not be initialized'); - $this->assertCount(2, $user->getPosts()); - $this->assertCount(2, $user->getPosts()->toArray()); + $posts = $user->getPosts(); + $this->assertInstanceOf(PersistentCollectionInterface::class, $posts); + $this->assertTrue($posts->isDirty(), 'A refreshed collection then modified should be dirty'); + $this->assertFalse($posts->isInitialized(), 'A refreshed collection then modified should not be initialized'); + $this->assertCount(2, $posts); + $this->assertCount(2, $posts->toArray()); - $user->getPosts()->initialize(); + $posts->initialize(); - $this->assertInstanceOf(PersistentCollectionInterface::class, $user->getPosts()); - $this->assertTrue($user->getPosts()->isDirty(), 'A dirty collection then initialized should remain dirty'); - $this->assertCount(2, $user->getPosts()); - $this->assertCount(2, $user->getPosts()->toArray()); + $this->assertTrue($posts->isDirty(), 'A dirty collection then initialized should remain dirty'); + $this->assertCount(2, $posts); + $this->assertCount(2, $posts->toArray()); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php index 9fc815ac1b..c3f66acd95 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM81Test.php @@ -84,12 +84,12 @@ class MODM81TestDocument */ protected $embeddedDocuments; - public function getId(): string + public function getId(): ?string { return $this->id; } - public function getName(): string + public function getName(): ?string { return $this->name; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM90Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM90Test.php index e384d430a8..979d4fff8c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM90Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM90Test.php @@ -70,6 +70,7 @@ public function testDiscriminatorFieldValuePresentIfRealProperty(): void $testDoc = $dm->find(MODM90TestDocument::class, $testDoc->id); + $this->assertInstanceOf(MODM90Test2EmbeddedDocument::class, $testDoc->embedded); $this->assertEquals('test2', $testDoc->embedded->type); } } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php index efdf73d24f..ce089a998c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php @@ -7,8 +7,11 @@ use Doctrine\ODM\MongoDB\Event\LoadClassMetadataEventArgs; use Doctrine\ODM\MongoDB\Events; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Tests\BaseTest; +use function assert; + class ClassMetadataLoadEventTest extends BaseTest { public function testEvent(): void @@ -27,6 +30,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void 'fieldName' => 'about', 'type' => 'string', ]; + assert($classMetadata instanceof ClassMetadata); $classMetadata->mapField($field); } } diff --git a/tests/Documents/File.php b/tests/Documents/File.php index 43c37bbe46..abf09cca73 100644 --- a/tests/Documents/File.php +++ b/tests/Documents/File.php @@ -73,7 +73,7 @@ public function getLength(): ?int return $this->length; } - public function getUploadDate(): DateTimeInterface + public function getUploadDate(): ?DateTimeInterface { return $this->uploadDate; } @@ -89,6 +89,6 @@ public function getOrCreateMetadata(): FileMetadata $this->metadata = new FileMetadata(); } - return $this->getMetadata(); + return $this->metadata; } } diff --git a/tests/Documents/FileMetadata.php b/tests/Documents/FileMetadata.php index 34202a5d1b..b5fae48265 100644 --- a/tests/Documents/FileMetadata.php +++ b/tests/Documents/FileMetadata.php @@ -20,7 +20,7 @@ final class FileMetadata /** * @ODM\EmbedOne(targetDocument=Embedded::class) * - * @var Embedded|null + * @var Embedded */ private $embedOne; diff --git a/tests/Documents/FileWithoutChunkSize.php b/tests/Documents/FileWithoutChunkSize.php index 01746c228d..06bd7748b1 100644 --- a/tests/Documents/FileWithoutChunkSize.php +++ b/tests/Documents/FileWithoutChunkSize.php @@ -73,7 +73,7 @@ public function getLength(): ?int return $this->length; } - public function getUploadDate(): DateTimeInterface + public function getUploadDate(): ?DateTimeInterface { return $this->uploadDate; } @@ -89,6 +89,6 @@ public function getOrCreateMetadata(): FileMetadata $this->metadata = new FileMetadata(); } - return $this->getMetadata(); + return $this->metadata; } } diff --git a/tests/Documents/SimpleReferenceUser.php b/tests/Documents/SimpleReferenceUser.php index 39cc6a54c0..e17d6ffec8 100644 --- a/tests/Documents/SimpleReferenceUser.php +++ b/tests/Documents/SimpleReferenceUser.php @@ -45,7 +45,7 @@ public function setUser(User $user): void $this->user = $user; } - public function getUser(): User + public function getUser(): ?User { return $this->user; } diff --git a/tests/Documents/User.php b/tests/Documents/User.php index b5bb8818f6..c38f2449c9 100644 --- a/tests/Documents/User.php +++ b/tests/Documents/User.php @@ -141,7 +141,7 @@ class User extends BaseDocument /** * @ODM\Field(type="int") * - * @var int|null + * @var int */ protected $hits = 0; diff --git a/tests/Documents/ViewReference.php b/tests/Documents/ViewReference.php index 4941e1005e..f2d505cc7b 100644 --- a/tests/Documents/ViewReference.php +++ b/tests/Documents/ViewReference.php @@ -14,7 +14,7 @@ class ViewReference /** * @ODM\Id * - * @var string|null + * @var string */ private $id;