1 | <?php |
||
10 | class ConfigurationFileRepository implements \ArrayAccess, \Iterator, \Countable |
||
11 | { |
||
12 | protected $files = []; |
||
13 | protected $secureBases = []; |
||
14 | protected $supportedTypes = []; |
||
15 | |||
16 | protected static $me; |
||
17 | |||
18 | protected function __construct() {} |
||
19 | |||
20 | 25 | public static function getInstance(array $secureBases = [], array $configurationFiles = []) |
|
34 | |||
35 | 31 | public static function reset() |
|
39 | |||
40 | 4 | protected function buildConfigurationFileList(array $configurationFiles, array $supportedTypes) |
|
41 | { |
||
42 | 4 | foreach ($configurationFiles as $file) { |
|
43 | 4 | $fileName = basename($file); |
|
44 | 4 | $typeFound = false; |
|
45 | 4 | foreach ($supportedTypes as $type) { |
|
46 | 4 | if (strpos($fileName, '.' . $type) !== false) { |
|
47 | 3 | $class = 'Magium\Configuration\File\Configuration\\' . ucfirst($type) . 'File'; |
|
48 | 3 | $configurationFile = new $class($file); |
|
49 | 2 | $this->registerConfigurationFile($configurationFile); |
|
50 | 2 | $typeFound = true; |
|
51 | } |
||
52 | } |
||
53 | 3 | if (!$typeFound) { |
|
54 | 1 | throw new UnsupportedFileTypeException( |
|
55 | 1 | sprintf( |
|
56 | 1 | 'File %s does not have a supported file extension: %s', |
|
57 | 1 | $file, |
|
58 | 1 | implode(',', $supportedTypes) |
|
59 | )) |
||
60 | ; |
||
61 | } |
||
62 | } |
||
63 | 2 | } |
|
64 | |||
65 | 4 | protected function getSupportedTypes(array $configurationFiles) |
|
84 | |||
85 | 6 | public function count() |
|
89 | |||
90 | 5 | public function registerConfigurationFile(AdapterInterface $file) |
|
91 | { |
||
92 | 5 | if (!isset($this->files[$file->getFile()])) { |
|
93 | 5 | $this->files[$file->getFile()] = $file; |
|
94 | } |
||
95 | |||
96 | 5 | } |
|
97 | |||
98 | 8 | public function addSecureBase($base) |
|
108 | |||
109 | 5 | protected function checkFileLocation(AdapterInterface $file) |
|
124 | |||
125 | /** |
||
126 | * Retrieves a list of secure base directories |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | |||
131 | 1 | public function getSecureBases() |
|
135 | |||
136 | 5 | public function current() |
|
142 | |||
143 | 4 | public function next() |
|
151 | |||
152 | 5 | public function key() |
|
156 | |||
157 | 5 | public function valid() |
|
163 | |||
164 | 5 | public function rewind() |
|
168 | |||
169 | public function offsetExists($offset) |
||
173 | |||
174 | public function offsetGet($offset) |
||
180 | |||
181 | public function offsetSet($offset, $value) |
||
185 | |||
186 | public function offsetUnset($offset) |
||
190 | |||
191 | } |
||
192 |
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.