mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Deleted dimension helper
This commit is contained in:
parent
102d5840d7
commit
56c0196326
@ -1,115 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helper;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* Helps to get all Elements till a special dimension.
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @todo Implement as service!
|
||||
*/
|
||||
final class DimensionHelper implements DimensionHelperInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $attribut;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $method;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $interface;
|
||||
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
private $object;
|
||||
|
||||
/**
|
||||
* @var int|null the actual dimension to which the class points
|
||||
*/
|
||||
private $dimension = null;
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* which uses the dimension helper
|
||||
* @param string $interface
|
||||
* which is implemented in all classes which have dimensions
|
||||
* @param object $object
|
||||
* which calls the dimension helper
|
||||
* @param string $attribut
|
||||
* which represents dimensions
|
||||
*/
|
||||
public function __construct(string $method, string $interface, object $object, string $attribut)
|
||||
{
|
||||
$this->method = $method;
|
||||
$this->interface = $interface;
|
||||
$this->object = $object;
|
||||
$this->attribut = $attribut;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* @param int $dimension
|
||||
* The dimensions start with 1 for the elements of the actuall dimension and NULL for all elements
|
||||
* @param Collection $elements
|
||||
* A elements collection, to which new elements should be add
|
||||
*
|
||||
* @return Collection Returns all elements till the defined dimension
|
||||
*/
|
||||
public function getDimensions(?int $dimension = null, Collection $elements = null): Collection
|
||||
{
|
||||
$this->setDimension($dimension);
|
||||
$elements = $elements ?? new ArrayCollection();
|
||||
if ($this->dimension >= 0) {
|
||||
foreach ($this->object->{$this->attributGetterName()}()
|
||||
->toArray() as $element) {
|
||||
if (!$elements->contains($element)) {
|
||||
$elements->add($element);
|
||||
if ($this->continueLoop() && $element instanceof $this->interface) {
|
||||
$element->{$this->method}($this->dimension, $elements);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
private function setDimension(?int $dimension): void
|
||||
{
|
||||
$this->dimension = is_int($dimension) ? $dimension - 1 : null;
|
||||
}
|
||||
|
||||
private function attributGetterName(): string
|
||||
{
|
||||
return 'get'.ucfirst($this->attribut);
|
||||
}
|
||||
|
||||
private function includeInfiniteDimensions(): bool
|
||||
{
|
||||
return is_null($this->dimension);
|
||||
}
|
||||
|
||||
private function isNotLastDimension(): bool
|
||||
{
|
||||
return $this->dimension > 0;
|
||||
}
|
||||
|
||||
private function continueLoop(): bool
|
||||
{
|
||||
return $this->includeInfiniteDimensions() || $this->isNotLastDimension();
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helper;
|
||||
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface DimensionHelperInterface
|
||||
{
|
||||
/**
|
||||
* @deprecated
|
||||
*
|
||||
* @param int $dimension
|
||||
* @param Collection $elements
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getDimensions(?int $dimension = null, Collection $elements = null): Collection;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Unit\Helper;
|
||||
|
||||
use App\Tests\AbstractTestCase;
|
||||
use App\Helper\DimensionHelper;
|
||||
use App\Helper\DimensionHelperInterface;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
class DimensionTest extends AbstractTestCase
|
||||
{
|
||||
/**
|
||||
* @var DimensionHelperInterface
|
||||
*/
|
||||
protected $dimensionMock;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->dimensionMock = new class() implements DimensionHelperInterface {
|
||||
/**
|
||||
* @var ArrayCollection
|
||||
*/
|
||||
public $dimensionElements;
|
||||
|
||||
/**
|
||||
* @var DimensionHelper
|
||||
*/
|
||||
public $dimensionHelper;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->dimensionElements = new ArrayCollection();
|
||||
$this->dimensionHelper = new DimensionHelper('getDimensions', DimensionHelperInterface::class, $this, 'dimensionElements');
|
||||
}
|
||||
|
||||
public function getDimensionElements(): Collection
|
||||
{
|
||||
return $this->dimensionElements;
|
||||
}
|
||||
|
||||
public function getDimensions(?int $dimension = null, Collection $elements = null): Collection
|
||||
{
|
||||
return $this->dimensionHelper->getDimensions($dimension, $elements);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private function getContinueLoopResult($dimension): bool
|
||||
{
|
||||
$this->setProperty($this->dimensionMock->dimensionHelper, 'dimension', $dimension);
|
||||
|
||||
return $this->invokeMethod($this->dimensionMock->dimensionHelper, 'continueLoop');
|
||||
}
|
||||
|
||||
public function testContinueLoop(): void
|
||||
{
|
||||
$this->assertTrue($this->getContinueLoopResult(null));
|
||||
$this->assertTrue($this->getContinueLoopResult(2));
|
||||
$this->assertTrue($this->getContinueLoopResult(1));
|
||||
$this->assertFalse($this->getContinueLoopResult(0));
|
||||
$this->assertFalse($this->getContinueLoopResult(-1));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user