Total Complexity | 9 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
10 | class Filesystem extends AbstractLoader |
||
11 | { |
||
12 | /** |
||
13 | * @return File[] |
||
14 | */ |
||
15 | 7 | public function getMediaFiles() |
|
16 | { |
||
17 | 7 | $path = $this->getBasePath(); |
|
18 | 7 | $contents = $this->getFilesystem()->listContents($path); |
|
19 | 7 | $directories = []; |
|
20 | 7 | $files = []; |
|
21 | 7 | foreach ($contents as $object) { |
|
22 | 5 | if ($object['type'] == 'dir') { |
|
23 | 1 | $directories[] = $object; |
|
24 | } else { |
||
25 | 4 | $files[] = $object; |
|
26 | } |
||
27 | } |
||
28 | 7 | if (count($directories) > 0) { |
|
29 | 1 | return $this->scanDirectoryContents($directories[0]['path']); |
|
30 | 6 | } elseif (count($files)) { |
|
31 | 4 | return $this->hydrateFileContents($files); |
|
32 | } |
||
33 | |||
34 | 2 | return []; |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * @param $path |
||
39 | * |
||
40 | * @return File[] |
||
41 | */ |
||
42 | 1 | protected function scanDirectoryContents($path) |
|
43 | { |
||
44 | 1 | $contents = $this->getFilesystem()->listContents($path); |
|
45 | |||
46 | 1 | return $this->hydrateFileContents($contents); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param $contents |
||
51 | * |
||
52 | * @return File[] |
||
53 | */ |
||
54 | 5 | protected function hydrateFileContents($contents) |
|
64 | } |
||
65 | } |
||
66 |