Total Complexity | 6 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Coverage | 17.65% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | trait IO |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $directory; |
||
27 | |||
28 | /** |
||
29 | * Glob without file sort. |
||
30 | * |
||
31 | * @param string $pattern |
||
32 | * |
||
33 | * @return array |
||
34 | */ |
||
35 | public function glob(string $pattern):array |
||
36 | { |
||
37 | $return = glob($this->getFullPath($pattern), GLOB_NOSORT); |
||
38 | |||
39 | if ($return === false) { |
||
40 | return []; |
||
41 | } |
||
42 | |||
43 | return $return; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Count files inside folder, if is a file, return 0. |
||
48 | * |
||
49 | * @param string $folder |
||
50 | * |
||
51 | * @return int |
||
52 | */ |
||
53 | public function getCount(string $folder):int |
||
54 | { |
||
55 | $path = $this->getFullPath($folder); |
||
56 | |||
57 | if (!is_dir($path)) { |
||
58 | $path = dirname($path); |
||
59 | } |
||
60 | |||
61 | $iterator = new FilesystemIterator( |
||
62 | $path, |
||
63 | FilesystemIterator::SKIP_DOTS |
||
64 | ); |
||
65 | |||
66 | return iterator_count($iterator); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Get full path. |
||
71 | * |
||
72 | * @param string $path |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | 1 | public function getFullPath(string $path):string |
|
83 | } |
||
84 | } |
||
85 |