| Total Complexity | 11 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class File |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @param string $path |
||
| 15 | * |
||
| 16 | * @throws \Helldar\Support\Exceptions\DirectoryNotFoundException |
||
| 17 | * |
||
| 18 | * @return array|\SplFileInfo[] |
||
| 19 | */ |
||
| 20 | public function all(string $path): array |
||
| 21 | { |
||
| 22 | if (Directory::doesntExist($path)) { |
||
| 23 | throw new DirectoryNotFoundException($path); |
||
| 24 | } |
||
| 25 | |||
| 26 | $dirs = new DirectoryIterator($path); |
||
| 27 | $items = []; |
||
| 28 | |||
| 29 | foreach ($dirs as $item) { |
||
| 30 | if ($item->isFile()) { |
||
| 31 | $items[] = $item->current(); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | return $items; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function store(string $path, string $content): void |
||
| 43 | } |
||
| 44 | |||
| 45 | public function exists(string $path): bool |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string|string[] $paths |
||
| 52 | * |
||
| 53 | * @return bool |
||
| 54 | */ |
||
| 55 | public function delete($paths): bool |
||
| 73 | } |
||
| 74 | } |
||
| 75 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: