mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-11-03 18:58:01 +00:00 
			
		
		
		
	Formated code
This commit is contained in:
		@@ -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;
 | 
				
			||||||
@@ -11,14 +12,12 @@ 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
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @var TreeCollectionSourceInterface
 | 
					     * @var TreeCollectionSourceInterface
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private $source;
 | 
					    private $source;
 | 
				
			||||||
@@ -67,7 +66,6 @@ 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}
 | 
				
			||||||
@@ -89,7 +87,7 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc
 | 
				
			|||||||
        foreach ((new self($branch))->getBranches() as $branchBranch) {
 | 
					        foreach ((new self($branch))->getBranches() as $branchBranch) {
 | 
				
			||||||
            if (!$allBranches->contains($branchBranch)) {
 | 
					            if (!$allBranches->contains($branchBranch)) {
 | 
				
			||||||
                $allBranches->add($branchBranch);
 | 
					                $allBranches->add($branchBranch);
 | 
				
			||||||
                if($branchBranch instanceof TreeCollectionSourceInterface){
 | 
					                if ($branchBranch instanceof TreeCollectionSourceInterface) {
 | 
				
			||||||
                    $this->itterateOverBranch($branchBranch, $allBranches);
 | 
					                    $this->itterateOverBranch($branchBranch, $allBranches);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@@ -106,11 +104,12 @@ final class TreeSourceService extends AbstractSourceService implements TreeSourc
 | 
				
			|||||||
        $leaves = new ArrayCollection($this->getLeaves()->toArray());
 | 
					        $leaves = new ArrayCollection($this->getLeaves()->toArray());
 | 
				
			||||||
        foreach ($this->getAllBranches() as $branch) {
 | 
					        foreach ($this->getAllBranches() 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,8 +1,8 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Tests\Unit\Domain;
 | 
					namespace Tests\Unit\Domain;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use PHPUnit\Framework\TestCase;
 | 
					use PHPUnit\Framework\TestCase;
 | 
				
			||||||
use App\Entity\Source\Collection\TreeCollectionSourceInterface;
 | 
					 | 
				
			||||||
use App\Entity\Source\Collection\TreeCollectionSource;
 | 
					use App\Entity\Source\Collection\TreeCollectionSource;
 | 
				
			||||||
use App\Entity\Source\SourceInterface;
 | 
					use App\Entity\Source\SourceInterface;
 | 
				
			||||||
use Doctrine\Common\Collections\ArrayCollection;
 | 
					use Doctrine\Common\Collections\ArrayCollection;
 | 
				
			||||||
@@ -12,12 +12,12 @@ use App\Domain\SourceManagement\TreeSourceService;
 | 
				
			|||||||
class TreeSourceServiceTest extends TestCase
 | 
					class TreeSourceServiceTest extends TestCase
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 
 | 
					 | 
				
			||||||
     * @var TreeSourceServiceInterface
 | 
					     * @var TreeSourceServiceInterface
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected $treeService;
 | 
					    protected $treeService;
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    public function setUp():void {
 | 
					    public function setUp(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        $tree1 = new TreeCollectionSource();
 | 
					        $tree1 = new TreeCollectionSource();
 | 
				
			||||||
        $tree2 = new TreeCollectionSource();
 | 
					        $tree2 = new TreeCollectionSource();
 | 
				
			||||||
        $tree3 = new TreeCollectionSource();
 | 
					        $tree3 = new TreeCollectionSource();
 | 
				
			||||||
@@ -28,26 +28,29 @@ class TreeSourceServiceTest extends TestCase
 | 
				
			|||||||
        $leave3 = $this->createMock(SourceInterface::class);
 | 
					        $leave3 = $this->createMock(SourceInterface::class);
 | 
				
			||||||
        $leave4 = $this->createMock(SourceInterface::class);
 | 
					        $leave4 = $this->createMock(SourceInterface::class);
 | 
				
			||||||
        $leave5 = $this->createMock(SourceInterface::class);
 | 
					        $leave5 = $this->createMock(SourceInterface::class);
 | 
				
			||||||
        $tree2->setCollection(new ArrayCollection([$leave3,$leave4,$tree5,$leave5]));
 | 
					        $tree2->setCollection(new ArrayCollection([$leave3, $leave4, $tree5, $leave5]));
 | 
				
			||||||
        $collection = new ArrayCollection([$tree2,$tree3,$leave1,$leave2,$tree4,$tree1]);
 | 
					        $collection = new ArrayCollection([$tree2, $tree3, $leave1, $leave2, $tree4, $tree1]);
 | 
				
			||||||
        $tree1->setCollection($collection);
 | 
					        $tree1->setCollection($collection);
 | 
				
			||||||
        $this->treeService = new TreeSourceService($tree1);
 | 
					        $this->treeService = new TreeSourceService($tree1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    public function testGetLeaves():void{
 | 
					    public function testGetLeaves(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        $this->assertEquals(2, $this->treeService->getLeaves()->count());
 | 
					        $this->assertEquals(2, $this->treeService->getLeaves()->count());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    public function testGetBranches():void{
 | 
					    public function testGetBranches(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        $this->assertEquals(4, $this->treeService->getBranches()->count());
 | 
					        $this->assertEquals(4, $this->treeService->getBranches()->count());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    public function testGetAllBranches():void{
 | 
					    public function testGetAllBranches(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        $this->assertEquals(5, $this->treeService->getAllBranches()->count());
 | 
					        $this->assertEquals(5, $this->treeService->getAllBranches()->count());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    public function testGetAllLeaves():void{
 | 
					    public function testGetAllLeaves(): void
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        $this->assertEquals(5, $this->treeService->getAllLeaves()->count());
 | 
					        $this->assertEquals(5, $this->treeService->getAllLeaves()->count());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user