From 56c01963267e040e1847dab3f77802ebf60e4b9f Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 18 Nov 2018 10:37:17 +0100 Subject: [PATCH] Deleted dimension helper --- application/src/Helper/DimensionHelper.php | 115 ------------------ .../src/Helper/DimensionHelperInterface.php | 23 ---- .../tests/Unit/Helper/DimensionTest.php | 64 ---------- 3 files changed, 202 deletions(-) delete mode 100644 application/src/Helper/DimensionHelper.php delete mode 100644 application/src/Helper/DimensionHelperInterface.php delete mode 100644 application/tests/Unit/Helper/DimensionTest.php diff --git a/application/src/Helper/DimensionHelper.php b/application/src/Helper/DimensionHelper.php deleted file mode 100644 index 3e2fb0e..0000000 --- a/application/src/Helper/DimensionHelper.php +++ /dev/null @@ -1,115 +0,0 @@ -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(); - } -} diff --git a/application/src/Helper/DimensionHelperInterface.php b/application/src/Helper/DimensionHelperInterface.php deleted file mode 100644 index 07ba73f..0000000 --- a/application/src/Helper/DimensionHelperInterface.php +++ /dev/null @@ -1,23 +0,0 @@ -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)); - } -}