diff --git a/module/Common/src/Collection/PathCollection.php b/module/Common/src/Collection/PathCollection.php deleted file mode 100644 index f1dca49a..00000000 --- a/module/Common/src/Collection/PathCollection.php +++ /dev/null @@ -1,65 +0,0 @@ -array = $array; - } - - public function pathExists(array $path): bool - { - return $this->checkPathExists($path, $this->array); - } - - private function checkPathExists(array $path, array $array): bool - { - // As soon as a step is not found, the path does not exist - $step = array_shift($path); - if (! array_key_exists($step, $array)) { - return false; - } - - // Once the path is empty, we have found all the parts in the path - if (empty($path)) { - return true; - } - - // If current value is not an array, then we have not found the path - $newArray = $array[$step]; - if (! is_array($newArray)) { - return false; - } - - return $this->checkPathExists($path, $newArray); - } - - /** - * @return mixed - */ - public function getValueInPath(array $path) - { - $array = $this->array; - - do { - $step = array_shift($path); - if (! is_array($array) || ! array_key_exists($step, $array)) { - return null; - } - - $array = $array[$step]; - } while (! empty($path)); - - return $array; - } -} diff --git a/module/Common/test/Collection/PathCollectionTest.php b/module/Common/test/Collection/PathCollectionTest.php deleted file mode 100644 index dee5d2e7..00000000 --- a/module/Common/test/Collection/PathCollectionTest.php +++ /dev/null @@ -1,80 +0,0 @@ -collection = new PathCollection([ - 'foo' => [ - 'bar' => [ - 'baz' => 'Hello world!', - ], - ], - 'something' => [], - 'another' => [ - 'one' => 'Shlink', - ], - ]); - } - - /** - * @test - * @dataProvider providePaths - */ - public function pathExistsReturnsExpectedValue(array $path, bool $expected) - { - $this->assertEquals($expected, $this->collection->pathExists($path)); - } - - public function providePaths(): array - { - return [ - [[], false], - [['boo'], false], - [['foo', 'nop'], false], - [['another', 'one', 'nop'], false], - [['foo'], true], - [['foo', 'bar'], true], - [['foo', 'bar', 'baz'], true], - [['something'], true], - ]; - } - - /** - * @test - * @dataProvider providePathsWithValue - */ - public function getValueInPathReturnsExpectedValue(array $path, $expected) - { - $this->assertEquals($expected, $this->collection->getValueInPath($path)); - } - - public function providePathsWithValue(): array - { - return [ - [[], null], - [['boo'], null], - [['foo', 'nop'], null], - [['another', 'one', 'nop'], null], - [['foo'], [ - 'bar' => [ - 'baz' => 'Hello world!', - ], - ]], - [['foo', 'bar'], [ - 'baz' => 'Hello world!', - ]], - [['foo', 'bar', 'baz'], 'Hello world!'], - [['something'], []], - ]; - } -}