mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 22:17:26 +01:00
Formated code
This commit is contained in:
parent
f1e78e7f5f
commit
2808fccdc9
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Domain;
|
namespace App\Domain;
|
||||||
|
|
||||||
abstract class AbstractDomainService
|
abstract class AbstractDomainService
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Domain\SourceManagement;
|
namespace App\Domain\SourceManagement;
|
||||||
|
|
||||||
use App\Domain\AbstractDomainService;
|
use App\Domain\AbstractDomainService;
|
||||||
@ -6,4 +7,3 @@ use App\Domain\AbstractDomainService;
|
|||||||
abstract class AbstractSourceService extends AbstractDomainService
|
abstract class AbstractSourceService extends AbstractDomainService
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Domain\SourceManagement;
|
namespace App\Domain\SourceManagement;
|
||||||
|
|
||||||
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
|
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
|
||||||
@ -8,9 +9,10 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||||||
use App\Entity\Source\SourceInterface;
|
use App\Entity\Source\SourceInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Allows to iterate over a tree.
|
||||||
* Allows to iterate over a tree
|
*
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
|
*
|
||||||
* @todo Maybe lazy loading would be helpfull for performance
|
* @todo Maybe lazy loading would be helpfull for performance
|
||||||
*/
|
*/
|
||||||
final class TreeSourceService extends AbstractSourceService implements TreeSourceServiceInterface
|
final class TreeSourceService extends AbstractSourceService implements TreeSourceServiceInterface
|
||||||
@ -19,38 +21,44 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc
|
|||||||
* @var TreeCollectionSourceInterface
|
* @var TreeCollectionSourceInterface
|
||||||
*/
|
*/
|
||||||
private $source;
|
private $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Containes all branches of the actual level of the tree
|
* Containes all branches of the actual level of the tree.
|
||||||
|
*
|
||||||
* @var Collection
|
* @var Collection
|
||||||
*/
|
*/
|
||||||
private $branches;
|
private $branches;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Containes all leaves of the actual level of the tree
|
* Containes all leaves of the actual level of the tree.
|
||||||
|
*
|
||||||
* @var Collection
|
* @var Collection
|
||||||
*/
|
*/
|
||||||
private $leaves;
|
private $leaves;
|
||||||
|
|
||||||
public function __construct(TreeCollectionSource $source){
|
public function __construct(TreeCollectionSource $source)
|
||||||
|
{
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
$this->branches = new ArrayCollection();
|
$this->branches = new ArrayCollection();
|
||||||
$this->leaves = new ArrayCollection();
|
$this->leaves = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sortMember(SourceInterface $member):bool{
|
private function sortMember(SourceInterface $member): bool
|
||||||
if($member instanceof TreeCollectionSource){
|
{
|
||||||
|
if ($member instanceof TreeCollectionSource) {
|
||||||
return $this->branches->add($member);
|
return $this->branches->add($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->leaves->add($member);
|
return $this->leaves->add($member);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function basicSort():void{
|
private function basicSort(): void
|
||||||
foreach($this->source->getCollection() as $member){
|
{
|
||||||
$this->sortMember($member);
|
foreach ($this->source->getCollection() as $member) {
|
||||||
|
$this->sortMember($member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBranches(): Collection
|
public function getBranches(): Collection
|
||||||
{
|
{
|
||||||
return $this->branches;
|
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 optional parameter and put the logic in a private funtion.
|
||||||
* @todo Remove the getAllBranches use inside the function.
|
* @todo Remove the getAllBranches use inside the function.
|
||||||
* {@inheritDoc}
|
* {@inheritdoc}
|
||||||
|
*
|
||||||
* @see \App\Domain\SourceManagement\TreeSourceServiceInterface::getAllBranches()
|
* @see \App\Domain\SourceManagement\TreeSourceServiceInterface::getAllBranches()
|
||||||
*/
|
*/
|
||||||
public function getAllBranches(): Collection
|
public function getAllBranches(): Collection
|
||||||
{
|
{
|
||||||
$allBranches = new ArrayCollection($this->branches->toArray());
|
$allBranches = new ArrayCollection($this->branches->toArray());
|
||||||
foreach($this->branches->toArray() as $branch){
|
foreach ($this->branches->toArray() as $branch) {
|
||||||
$this->itterateOverBranch($branch, $allBranches);
|
$this->itterateOverBranch($branch, $allBranches);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $allBranches;
|
return $allBranches;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function itterateOverBranch(TreeCollectionSourceInterface $branch,ArrayCollection $allBranches):void{
|
private function itterateOverBranch(TreeCollectionSourceInterface $branch, ArrayCollection $allBranches): void
|
||||||
if(!$allBranches->contains($branch)){
|
{
|
||||||
|
if (!$allBranches->contains($branch)) {
|
||||||
$allBranches->add($branch);
|
$allBranches->add($branch);
|
||||||
foreach((new self($branch))->getBranches() as $branchBranch){
|
foreach ((new self($branch))->getBranches() as $branchBranch) {
|
||||||
$allBranches->add($branchBranch);
|
$allBranches->add($branchBranch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getLeaves(): Collection
|
public function getLeaves(): Collection
|
||||||
{
|
{
|
||||||
return $this->leaves;
|
return $this->leaves;
|
||||||
@ -89,14 +99,14 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc
|
|||||||
public function getAllLeaves(): Collection
|
public function getAllLeaves(): Collection
|
||||||
{
|
{
|
||||||
$leaves = new ArrayCollection();
|
$leaves = new ArrayCollection();
|
||||||
foreach ($this->getAllBranches()->toArray() as $branch){
|
foreach ($this->getAllBranches()->toArray() as $branch) {
|
||||||
foreach ((new self($branch))->getLeaves() as $leave){
|
foreach ((new self($branch))->getLeaves() as $leave) {
|
||||||
if(!$leaves->contains($leave)){
|
if (!$leaves->contains($leave)) {
|
||||||
$leaves->add($leave);
|
$leaves->add($leave);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $leaves;
|
return $leaves;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Domain\SourceManagement;
|
namespace App\Domain\SourceManagement;
|
||||||
|
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
@ -6,27 +7,30 @@ use Doctrine\Common\Collections\Collection;
|
|||||||
interface TreeSourceServiceInterface
|
interface TreeSourceServiceInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Delivers the branches of the actual tree back
|
* Delivers the branches of the actual tree back.
|
||||||
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getBranches():Collection;
|
public function getBranches(): Collection;
|
||||||
|
|
||||||
/**
|
|
||||||
* Delivers the members of the actual tree back
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getLeaves():Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delivers all members till a infinite level of the tree back
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getAllLeaves():Collection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delivers all branches till a infinite level of the actual tree back
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getAllBranches():Collection;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delivers the members of the actual tree back.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getLeaves(): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delivers all members till a infinite level of the tree back.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAllLeaves(): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delivers all branches till a infinite level of the actual tree back.
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getAllBranches(): Collection;
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Exception;
|
namespace App\Exception;
|
||||||
|
|
||||||
class NotSortableException extends \Exception
|
class NotSortableException extends \Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user