Total Complexity | 10 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class Folder |
||
9 | { |
||
10 | private string $path; |
||
11 | |||
12 | public function __construct(string $path) |
||
13 | { |
||
14 | $this->setPath($path); |
||
15 | } |
||
16 | |||
17 | public function sanitize() |
||
18 | { |
||
19 | return PathSanitizer::sanitize($this->path); |
||
20 | } |
||
21 | |||
22 | public function read(int $level) : array |
||
23 | { |
||
24 | return FolderReader::read($this->path, $level); |
||
25 | } |
||
26 | |||
27 | public function create() |
||
28 | { |
||
29 | if ($this->exists()) { |
||
30 | return true; |
||
31 | } |
||
32 | |||
33 | mkdir($this->path, 0755, true); |
||
34 | } |
||
35 | |||
36 | public function delete(string $path = null) |
||
37 | { |
||
38 | $folder = $path ?? $this->path; |
||
39 | |||
40 | $files = array_diff(scandir($folder), array('.', '..')); |
||
41 | |||
42 | foreach ($files as $file) { |
||
43 | |||
44 | $item = "$folder/$file"; |
||
45 | |||
46 | is_dir($item) ? $this->delete($item) : unlink($item); |
||
47 | } |
||
48 | |||
49 | return rmdir($folder); |
||
50 | } |
||
51 | |||
52 | public function exists() : bool |
||
53 | { |
||
54 | return (is_dir($this->path)); |
||
55 | } |
||
56 | |||
57 | private function setPath(string $path) |
||
61 | } |
||
62 | } |