bavix /
helpers
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Bavix\Helpers; |
||||
| 4 | |||||
| 5 | class Dir |
||||
| 6 | { |
||||
| 7 | |||||
| 8 | /** |
||||
| 9 | * @param string $path |
||||
| 10 | * |
||||
| 11 | * @return bool |
||||
| 12 | */ |
||||
| 13 | 1 | public static function make($path) |
|||
| 14 | { |
||||
| 15 | 1 | return is_dir($path) || @mkdir($path, 0777, true); |
|||
| 16 | } |
||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * @param string $path |
||||
| 20 | * |
||||
| 21 | * @return bool |
||||
| 22 | */ |
||||
| 23 | 2 | public static function isDir($path) |
|||
| 24 | { |
||||
| 25 | 2 | return is_dir($path); |
|||
| 26 | } |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * @param string $path |
||||
| 30 | * @param bool $recursive |
||||
| 31 | * |
||||
| 32 | * @return bool |
||||
| 33 | */ |
||||
| 34 | 1 | public static function remove($path, $recursive = false) |
|||
| 35 | { |
||||
| 36 | 1 | $path = \rtrim($path, '/') . '/'; |
|||
| 37 | |||||
| 38 | 1 | if ($recursive) |
|||
| 39 | { |
||||
| 40 | |||||
| 41 | 1 | $storage = \array_merge( |
|||
| 42 | 1 | \glob($path . '*'), |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 43 | 1 | \glob($path . '.*') |
|||
|
0 ignored issues
–
show
It seems like
glob($path . '.*') can also be of type false; however, parameter $array2 of array_merge() does only seem to accept array|null, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 44 | ); |
||||
| 45 | |||||
| 46 | 1 | foreach ($storage as $item) |
|||
| 47 | { |
||||
| 48 | |||||
| 49 | 1 | if (in_array(basename($item), ['.', '..'], true)) |
|||
| 50 | { |
||||
| 51 | 1 | continue; |
|||
| 52 | } |
||||
| 53 | |||||
| 54 | 1 | if (static::isDir($item)) |
|||
| 55 | { |
||||
| 56 | 1 | static::remove($item, $recursive); |
|||
| 57 | 1 | continue; |
|||
| 58 | } |
||||
| 59 | |||||
| 60 | 1 | File::remove($item); |
|||
| 61 | |||||
| 62 | } |
||||
| 63 | |||||
| 64 | } |
||||
| 65 | |||||
| 66 | 1 | return rmdir($path); |
|||
| 67 | } |
||||
| 68 | |||||
| 69 | } |
||||
| 70 |