diff --git a/application/src/Domain/SourceManagement/SourceMemberInformation.php b/application/src/Domain/SourceManagement/SourceMemberInformation.php new file mode 100644 index 0000000..46ac8ee --- /dev/null +++ b/application/src/Domain/SourceManagement/SourceMemberInformation.php @@ -0,0 +1,43 @@ +source = $source; + } + + private function itterateOverMembers(Collection $members): void + { + foreach ($members as $member) { + if (!$this->members->contains($member)) { + $this->members->add($member); + $this->itterateOverMembers($member->getMemberRelation()->getMembers()); + } + } + } + + public function getAllMembers(): Collection + { + $this->members = new ArrayCollection(); + $this->itterateOverMembers($this->source->getMemberRelation()->getMembers()); + + return $this->members; + } +} diff --git a/application/src/Domain/SourceManagement/SourceMemberInformationInterface.php b/application/src/Domain/SourceManagement/SourceMemberInformationInterface.php new file mode 100644 index 0000000..093b3f4 --- /dev/null +++ b/application/src/Domain/SourceManagement/SourceMemberInformationInterface.php @@ -0,0 +1,14 @@ +memberRelation->setSource($this); $this->law = new Law(); $this->law->setSource($this); - /* - * - * @todo Refactor the following attibutes - */ - $this->memberships = new ArrayCollection(); - $this->members = new ArrayCollection(); } } diff --git a/application/tests/Unit/Domain/SourceManagement/SourceMemberInformationTest.php b/application/tests/Unit/Domain/SourceManagement/SourceMemberInformationTest.php new file mode 100644 index 0000000..f57319a --- /dev/null +++ b/application/tests/Unit/Domain/SourceManagement/SourceMemberInformationTest.php @@ -0,0 +1,57 @@ +source = new UserSource(); + $this->sourceMemberInformation = new SourceMemberInformation($this->source); + } + + public function testOneDimension(): void + { + $this->source->getMemberRelation()->getMembers()->add(new TextSource()); + $this->assertEquals(1, $this->sourceMemberInformation->getAllMembers()->count()); + } + + public function testThreeDimension(): void + { + $source1 = new TextSource(); + $source2 = new FirstNameSource(); + $source2->getMemberRelation()->setMembers(new ArrayCollection([$source1])); + $source3 = new FullPersonNameSource(); + $source3->getMemberRelation()->getMembers()->add($source2); + $this->source->getMemberRelation()->getMembers()->add($source3); + $this->assertEquals(3, $this->sourceMemberInformation->getAllMembers()->count()); + } + + public function testRecursion(): void + { + $recursiveSource = new UserSource(); + $recursiveSource->getMemberRelation()->getMembers()->add($this->source); + $this->source->getMemberRelation()->getMembers()->add($recursiveSource); + $this->assertEquals(2, $this->sourceMemberInformation->getAllMembers()->count()); + } +}