Skip to content

Commit 0c0f04b

Browse files
authored
Add more phpdoc type info (#2330)
1 parent e00e9e9 commit 0c0f04b

File tree

8 files changed

+75
-14
lines changed

8 files changed

+75
-14
lines changed

tests/Doctrine/ODM/MongoDB/Tests/Functional/AtomicSetTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ public function testReplacementOfEmbedManyElements()
453453
$firstChapter->name = 'First chapter A';
454454

455455
// Developers commonly attempt to replace the contents of an EmbedMany with a new ArrayCollection like this:
456+
/** @var ArrayCollection<int, Chapter> $replacementChapters */
456457
$replacementChapters = new ArrayCollection();
457458
$replacementChapters->add($firstChapter);
458459
$replacementChapters->add(new Chapter('Second chapter B'));
@@ -478,9 +479,10 @@ public function testReplacementOfIdentifiedEmbedManyElements()
478479
$this->dm->flush();
479480
$this->dm->clear();
480481

481-
$book = $this->dm->getRepository(Book::CLASSNAME)->findOneBy(['_id' => $book->id]);
482-
$firstChapter = $book->identifiedChapters->first();
483-
$firstChapter->name = 'First chapter A';
482+
$book = $this->dm->getRepository(Book::CLASSNAME)->findOneBy(['_id' => $book->id]);
483+
$firstChapter = $book->identifiedChapters->first();
484+
$firstChapter->name = 'First chapter A';
485+
/** @var ArrayCollection<int, IdentifiedChapter> $replacementChapters */
484486
$replacementChapters = new ArrayCollection();
485487
$replacementChapters->add($firstChapter);
486488
$replacementChapters->add(new IdentifiedChapter('Second chapter B'));

tests/Doctrine/ODM/MongoDB/Tests/Functional/EmbeddedTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ODM\MongoDB\Tests\Functional;
66

77
use Doctrine\Common\Collections\ArrayCollection;
8+
use Doctrine\Common\Collections\Collection;
89
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
910
use Doctrine\ODM\MongoDB\PersistentCollection;
1011
use Doctrine\ODM\MongoDB\Tests\BaseTest;
@@ -560,6 +561,8 @@ public function testWhenCopyingManyEmbedSubDocumentsFromOneDocumentToAnotherWill
560561
$this->dm->persist($test1);
561562
$this->dm->flush();
562563

564+
assert($test1->embedMany instanceof Collection);
565+
563566
$test2 = new ChangeEmbeddedIdTest();
564567
$test2->embedMany = $test1->embedMany; //using clone will work
565568
$this->dm->persist($test2);
@@ -642,10 +645,18 @@ class ChangeEmbeddedIdTest
642645
/** @ODM\Id */
643646
public $id;
644647

645-
/** @ODM\EmbedOne(targetDocument=EmbeddedDocumentWithId::class) */
648+
/**
649+
* @ODM\EmbedOne(targetDocument=EmbeddedDocumentWithId::class)
650+
*
651+
* @var EmbeddedDocumentWithId|null
652+
*/
646653
public $embed;
647654

648-
/** @ODM\EmbedMany(targetDocument=EmbeddedDocumentWithId::class) */
655+
/**
656+
* @ODM\EmbedMany(targetDocument=EmbeddedDocumentWithId::class)
657+
*
658+
* @var Collection<int, EmbeddedDocumentWithId>|array<EmbeddedDocumentWithId>
659+
*/
649660
public $embedMany;
650661

651662
public function __construct()

tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferenceEmbeddedDocumentsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function testSavesEmbeddedDocumentsInReferencedDocument()
2222

2323
$project = $this->dm->find(Project::class, $project->getId());
2424

25+
/** @var ArrayCollection<int, SubProject> $subProjects */
2526
$subProjects = new ArrayCollection();
2627
$subProject1 = new SubProject('Sub Project #1');
2728
$subProject2 = new SubProject('Sub Project #2');

tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1011Test.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;
66

77
use Doctrine\Common\Collections\ArrayCollection;
8+
use Doctrine\Common\Collections\Collection;
89
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
910
use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface;
1011
use Doctrine\ODM\MongoDB\Tests\BaseTest;
@@ -20,6 +21,7 @@ public function testClearCollection()
2021
$doc->embeds->clear();
2122
$doc->embeds->add(new GH1011Embedded('test2'));
2223
$this->uow->computeChangeSets();
24+
$this->assertInstanceOf(PersistentCollectionInterface::class, $doc->embeds);
2325
$this->assertTrue($this->uow->isCollectionScheduledForUpdate($doc->embeds));
2426
$this->assertFalse($this->uow->isCollectionScheduledForDeletion($doc->embeds));
2527
}
@@ -47,7 +49,11 @@ class GH1011Document
4749
/** @ODM\Id */
4850
public $id;
4951

50-
/** @ODM\EmbedMany(targetDocument=GH1011Embedded::class, strategy="set") */
52+
/**
53+
* @ODM\EmbedMany(targetDocument=GH1011Embedded::class, strategy="set")
54+
*
55+
* @var Collection<int, GH1011Embedded>
56+
*/
5157
public $embeds;
5258

5359
public function __construct()

tests/Documents/Book.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Documents;
66

77
use Doctrine\Common\Collections\ArrayCollection;
8+
use Doctrine\Common\Collections\Collection;
89
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
910

1011
/** @ODM\Document */
@@ -18,10 +19,18 @@ class Book
1819
/** @ODM\Field(type="int") @ODM\Version */
1920
public $version = 1;
2021

21-
/** @ODM\EmbedMany(targetDocument=Chapter::class, strategy="atomicSet") */
22+
/**
23+
* @ODM\EmbedMany(targetDocument=Chapter::class, strategy="atomicSet")
24+
*
25+
* @var Collection<int, Chapter>
26+
*/
2227
public $chapters;
2328

24-
/** @ODM\EmbedMany(targetDocument=IdentifiedChapter::class, strategy="atomicSet") */
29+
/**
30+
* @ODM\EmbedMany(targetDocument=IdentifiedChapter::class, strategy="atomicSet")
31+
*
32+
* @var Collection<int, IdentifiedChapter>
33+
*/
2534
public $identifiedChapters;
2635

2736
public function __construct()

tests/Documents/IdentifiedChapter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Documents;
66

77
use Doctrine\Common\Collections\ArrayCollection;
8+
use Doctrine\Common\Collections\Collection;
89
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
910

1011
/** @ODM\EmbeddedDocument */
@@ -16,7 +17,11 @@ class IdentifiedChapter
1617
/** @ODM\Field(type="string") */
1718
public $name;
1819

19-
/** @ODM\EmbedMany(targetDocument=Page::class) */
20+
/**
21+
* @ODM\EmbedMany(targetDocument=Page::class)
22+
*
23+
* @var Collection<int, Page>
24+
*/
2025
public $pages;
2126

2227
public function __construct($name = null)

tests/Documents/Project.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,27 @@ class Project
2222
/** @ODM\Field(type="string") */
2323
private $name;
2424

25-
/** @ODM\EmbedOne(targetDocument=Address::class) */
25+
/**
26+
* @ODM\EmbedOne(targetDocument=Address::class)
27+
*
28+
* @var Address|null
29+
*/
2630
private $address;
2731

28-
/** @ODM\ReferenceMany(targetDocument=SubProject::class, cascade="all") */
32+
/**
33+
* @ODM\ReferenceMany(targetDocument=SubProject::class, cascade="all")
34+
*
35+
* @var Collection<int, SubProject>
36+
*/
2937
private $subProjects;
3038

31-
public function __construct($name, ?Collection $subProjects = null)
39+
/**
40+
* @param Collection<int, SubProject>|null $subProjects
41+
*/
42+
public function __construct(string $name, ?Collection $subProjects = null)
3243
{
3344
$this->name = $name;
34-
$this->subProjects = $subProjects ? $subProjects : new ArrayCollection();
45+
$this->subProjects = $subProjects ?? new ArrayCollection();
3546
}
3647

3748
public function getId()
@@ -59,11 +70,17 @@ public function getAddress()
5970
return $this->address;
6071
}
6172

73+
/**
74+
* @param Collection<int, SubProject> $subProjects
75+
*/
6276
public function setSubProjects(Collection $subProjects)
6377
{
6478
$this->subProjects = $subProjects;
6579
}
6680

81+
/**
82+
* @return Collection<int, SubProject>
83+
*/
6784
public function getSubProjects()
6885
{
6986
return $this->subProjects;

tests/Documents/SubProject.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,24 @@
1010
/** @ODM\Document */
1111
class SubProject extends Project
1212
{
13-
/** @ODM\EmbedMany(targetDocument=Issue::class) */
13+
/**
14+
* @ODM\EmbedMany(targetDocument=Issue::class)
15+
*
16+
* @var Collection<int, Issue>
17+
*/
1418
private $issues;
1519

20+
/**
21+
* @return Collection<int, Issue>
22+
*/
1623
public function getIssues()
1724
{
1825
return $this->issues;
1926
}
2027

28+
/**
29+
* @param Collection<int, Issue> $issues
30+
*/
2131
public function setIssues(Collection $issues)
2232
{
2333
$this->issues = $issues;

0 commit comments

Comments
 (0)