diff --git a/application/src/Domain/AbstractDomainService.php b/application/src/Domain/AbstractDomainService.php index 8992f3a..6a0381c 100644 --- a/application/src/Domain/AbstractDomainService.php +++ b/application/src/Domain/AbstractDomainService.php @@ -1,7 +1,7 @@ source = $source; $this->branches = new ArrayCollection(); $this->leaves = new ArrayCollection(); } - - private function sortMember(SourceInterface $member):bool{ - if($member instanceof TreeCollectionSource){ + + private function sortMember(SourceInterface $member): bool + { + if ($member instanceof TreeCollectionSource) { return $this->branches->add($member); } + return $this->leaves->add($member); } - - private function basicSort():void{ - foreach($this->source->getCollection() as $member){ - $this->sortMember($member); + + private function basicSort(): void + { + foreach ($this->source->getCollection() as $member) { + $this->sortMember($member); } } - + public function getBranches(): Collection { return $this->branches; @@ -58,29 +66,31 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc /** * @todo Remove the optional parameter and put the logic in a private funtion. - * @todo Remove the getAllBranches use inside the function. - * {@inheritDoc} + * @todo Remove the getAllBranches use inside the function. + * {@inheritdoc} + * * @see \App\Domain\SourceManagement\TreeSourceServiceInterface::getAllBranches() */ public function getAllBranches(): Collection { $allBranches = new ArrayCollection($this->branches->toArray()); - foreach($this->branches->toArray() as $branch){ + foreach ($this->branches->toArray() as $branch) { $this->itterateOverBranch($branch, $allBranches); } + return $allBranches; } - - private function itterateOverBranch(TreeCollectionSourceInterface $branch,ArrayCollection $allBranches):void{ - if(!$allBranches->contains($branch)){ + + private function itterateOverBranch(TreeCollectionSourceInterface $branch, ArrayCollection $allBranches): void + { + if (!$allBranches->contains($branch)) { $allBranches->add($branch); - foreach((new self($branch))->getBranches() as $branchBranch){ + foreach ((new self($branch))->getBranches() as $branchBranch) { $allBranches->add($branchBranch); } } } - - + public function getLeaves(): Collection { return $this->leaves; @@ -89,14 +99,14 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc public function getAllLeaves(): Collection { $leaves = new ArrayCollection(); - foreach ($this->getAllBranches()->toArray() as $branch){ - foreach ((new self($branch))->getLeaves() as $leave){ - if(!$leaves->contains($leave)){ + foreach ($this->getAllBranches()->toArray() as $branch) { + foreach ((new self($branch))->getLeaves() as $leave) { + if (!$leaves->contains($leave)) { $leaves->add($leave); } } } + return $leaves; } - -} \ No newline at end of file +} diff --git a/application/src/Domain/SourceManagement/TreeSourceServiceInterface.php b/application/src/Domain/SourceManagement/TreeSourceServiceInterface.php index 8aa7da9..9cadc83 100644 --- a/application/src/Domain/SourceManagement/TreeSourceServiceInterface.php +++ b/application/src/Domain/SourceManagement/TreeSourceServiceInterface.php @@ -1,4 +1,5 @@