Conditions | 10 |
Paths | 34 |
Total Lines | 42 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
15 | public function __construct(array $secureBases = [], array $configurationFiles = []) |
||
16 | { |
||
17 | foreach ($secureBases as $base) { |
||
18 | $this->addSecureBase($base); |
||
19 | } |
||
20 | |||
21 | $supportedTypes = []; |
||
22 | if (!empty($configurationFiles)) { |
||
23 | $checkSupportedTypes = glob(__DIR__ . '/*File.php'); |
||
24 | foreach ($checkSupportedTypes as $file) { |
||
25 | $file = basename($file); |
||
26 | if ($file != 'AbstractConfigurationFile.php') { |
||
27 | $match = null; |
||
28 | if (preg_match('/^([a-zA-Z]+)File.php$/', $file, $match)) { |
||
29 | $supportedTypes[] = strtolower($match[1]); |
||
30 | } |
||
31 | } |
||
32 | } |
||
33 | } |
||
34 | |||
35 | foreach ($configurationFiles as $file) { |
||
36 | $fileName = basename($file); |
||
37 | $typeFound = false; |
||
38 | foreach ($supportedTypes as $type) { |
||
39 | if (strpos($fileName, '.' . $type) !== false) { |
||
40 | $class = 'Magium\Configuration\File\Configuration\\' . ucfirst($type) . 'File'; |
||
41 | $configurationFile = new $class($file); |
||
42 | $this->registerConfigurationFile($configurationFile); |
||
43 | $typeFound = true; |
||
44 | } |
||
45 | } |
||
46 | if (!$typeFound) { |
||
47 | throw new UnsupportedFileTypeException( |
||
48 | sprintf( |
||
49 | 'File %s does not have a supported file extension: %s', |
||
50 | $file, |
||
51 | implode(',', $supportedTypes) |
||
52 | )) |
||
53 | ; |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | |||
163 |