Total Complexity | 15 |
Total Lines | 88 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | class Loader |
||
9 | { |
||
10 | protected $filepath; |
||
11 | protected $isloaded = false; |
||
12 | protected $extension; |
||
13 | protected $strict = false; |
||
14 | |||
15 | public function __construct($path, $extension) |
||
19 | } |
||
20 | |||
21 | public function getLoadStatus() |
||
24 | } |
||
25 | |||
26 | public function getFile() |
||
29 | } |
||
30 | |||
31 | public function run() |
||
32 | { |
||
33 | $this->isloaded = true; |
||
34 | |||
35 | $content = null; |
||
36 | |||
37 | $path = glob($this->filepath); |
||
38 | |||
39 | if (empty($path) || !$path) { |
||
|
|||
40 | $this->isloaded = false; |
||
41 | return false; |
||
42 | } |
||
43 | |||
44 | foreach ($path as $filemain) |
||
45 | { |
||
46 | $fileInfo = pathinfo($filemain); |
||
47 | |||
48 | $pathInfo = $fileInfo['dirname'].DIRECTORY_SEPARATOR.$fileInfo['basename']; |
||
49 | |||
50 | if (is_dir($pathInfo)) { |
||
51 | $dirlist = @scandir($pathInfo); |
||
52 | |||
53 | foreach ($dirlist as $file) { |
||
54 | |||
55 | $fileInfoFolder = pathinfo($file); |
||
56 | |||
57 | $pathInfoFolder = $fileInfoFolder['dirname'].DIRECTORY_SEPARATOR.$fileInfoFolder['basename']; |
||
58 | |||
59 | if ($this->isReadable($path)) { |
||
60 | |||
61 | if (in_array($fileInfoFolder['extension'], $this->extension)) { |
||
62 | |||
63 | $content .= file_get_contents($pathInfoFolder); |
||
64 | |||
65 | } else { |
||
66 | |||
67 | throw new Exception('Invalid extension'); |
||
68 | |||
69 | } |
||
70 | |||
71 | } |
||
72 | |||
73 | } |
||
74 | |||
75 | } else { |
||
76 | |||
77 | if (is_readable($pathInfo)) { |
||
78 | |||
79 | $content .= file_get_contents($pathInfo); |
||
80 | } |
||
81 | |||
82 | } |
||
83 | |||
84 | } |
||
85 | |||
86 | return $content; |
||
87 | } |
||
88 | |||
89 | private function isReadable($path) |
||
96 | } |
||
97 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.