| Total Complexity | 9 |
| Total Lines | 84 |
| Duplicated Lines | 0 % |
| Coverage | 40% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class ArrayLocator implements ArrayLocatorInterface |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | private $array; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | private $fieldMap; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * ArrayLocator constructor. |
||
| 21 | */ |
||
| 22 | 1 | public function __construct() |
|
| 23 | { |
||
| 24 | 1 | $this->array = []; |
|
| 25 | 1 | $this->fieldMap = []; |
|
| 26 | 1 | } |
|
| 27 | |||
| 28 | |||
| 29 | /** |
||
| 30 | * ArrayLocator constructor. |
||
| 31 | * |
||
| 32 | * @param array $array |
||
| 33 | */ |
||
| 34 | public function init(array $array) |
||
| 35 | { |
||
| 36 | $this->array = $array; |
||
| 37 | $this->fieldMap = []; |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param string $path |
||
| 42 | * |
||
| 43 | * @return array |
||
| 44 | */ |
||
| 45 | 1 | public function getKeysByPath(string $path) |
|
| 46 | { |
||
| 47 | 1 | if ($this->fieldMap === null) { |
|
| 48 | $this->buildFieldMap(); |
||
| 49 | } |
||
| 50 | |||
| 51 | 1 | return $this->getAllKeys($this->fieldMap, $path); |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param $array |
||
| 56 | * @param $path |
||
| 57 | * |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | 1 | protected function getAllKeys($array, $path): array |
|
| 64 | } |
||
| 65 | |||
| 66 | protected function buildFieldMap(): void |
||
| 67 | { |
||
| 68 | $this->fieldMap = $this->getAllFields($this->array, '', []); |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @param array $array |
||
| 73 | * @param string $path |
||
| 74 | * @param array $fieldMap |
||
| 75 | * |
||
| 76 | * @return array |
||
| 77 | */ |
||
| 78 | protected function getAllFields(array $array, string $path, array $fieldMap): array |
||
| 91 | } |
||
| 92 | } |