| Total Complexity | 6 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | class FindFreeName |
||
| 17 | { |
||
| 18 | protected const FREE_NAME_SEPARATOR = '_'; |
||
| 19 | |||
| 20 | protected Interfaces\IProcessNodes $nodes; |
||
| 21 | |||
| 22 | 10 | public function __construct(Interfaces\IProcessNodes $nodes) |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string[] $path |
||
| 29 | * @param string $name |
||
| 30 | * @param string $suffix |
||
| 31 | * @throws FilesException |
||
| 32 | * @throws PathsException |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | 10 | public function findFreeName(array $path, string $name, string $suffix): string |
|
| 36 | { |
||
| 37 | 10 | if (!$this->targetExists($path, $name . $suffix)) { |
|
| 38 | 4 | return $name . $suffix; |
|
| 39 | } |
||
| 40 | 6 | $i = 0; |
|
| 41 | 6 | while ($this->targetExists($path, $name . $this->getNameSeparator() . strval($i) . $suffix)) { |
|
| 42 | 2 | $i++; |
|
| 43 | } |
||
| 44 | 6 | return $name . $this->getNameSeparator() . strval($i) . $suffix; |
|
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param array<string> $path |
||
| 49 | * @param string $name |
||
| 50 | * @throws FilesException |
||
| 51 | * @throws PathsException |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | 10 | protected function targetExists(array $path, string $name): bool |
|
| 57 | } |
||
| 58 | |||
| 59 | 3 | protected function getNameSeparator(): string |
|
| 62 | } |
||
| 63 | } |
||
| 64 |