| Total Complexity | 11 |
| Total Lines | 81 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | class ArrayPath |
||
| 14 | { |
||
| 15 | /** @var string[] */ |
||
| 16 | protected array $path = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @throws PathsException |
||
| 20 | * @return string |
||
| 21 | */ |
||
| 22 | 3 | public function __toString() |
|
| 23 | { |
||
| 24 | 3 | return $this->getString(); |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $path |
||
| 29 | * @throws PathsException |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | 2 | public function setString(string $path): self |
|
| 33 | { |
||
| 34 | 2 | $this->path = array_filter(array_filter(Stuff::pathToArray($path), [Stuff::class, 'notDots'])); |
|
| 35 | 2 | return $this; |
|
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param string[] $path |
||
| 40 | * @return $this |
||
| 41 | */ |
||
| 42 | 1 | public function setArray(array $path): self |
|
| 43 | { |
||
| 44 | 1 | $this->path = array_filter(array_filter($path, [Stuff::class, 'notDots'])); |
|
| 45 | 1 | return $this; |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @throws PathsException |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | 3 | public function getString(): string |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return string[] |
||
| 59 | */ |
||
| 60 | 3 | public function getArray(): array |
|
| 61 | { |
||
| 62 | 3 | return array_merge($this->path, []); // remove indexes |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @throws PathsException |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 3 | public function getStringDirectory(): string |
|
| 70 | { |
||
| 71 | 3 | $array = $this->getArrayDirectory(); |
|
| 72 | 3 | return empty($array) |
|
| 73 | 2 | ? '' |
|
| 74 | 3 | : Stuff::arrayToPath($array) |
|
| 75 | 3 | ; |
|
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return string[] |
||
| 80 | */ |
||
| 81 | 3 | public function getArrayDirectory(): array |
|
| 82 | { |
||
| 83 | 3 | return (1 < count($this->path)) |
|
| 84 | 1 | ? array_slice($this->path, 0, -1) |
|
| 85 | 3 | : [] |
|
| 86 | 3 | ; |
|
| 87 | } |
||
| 88 | |||
| 89 | 3 | public function getFileName(): string |
|
| 94 | 3 | ; |
|
| 95 | } |
||
| 96 | } |
||
| 97 |