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