| Conditions | 11 | 
| Paths | 13 | 
| Total Lines | 33 | 
| Code Lines | 18 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | ||
| 39 | public static function getConfigFromFile(string $fileName): array | ||
| 40 |     { | ||
| 41 | $fileName .= self::PHP_SUFFIX; | ||
| 42 | $currentEnv = Craft::$app->getConfig()->env; | ||
| 43 | // Try craft/config first | ||
| 44 |         $path = Craft::getAlias('@config/' . $fileName, false); | ||
| 45 |         if ($path === false || !file_exists($path)) { | ||
| 46 | // Now try our own internal config | ||
| 47 |             $path = Craft::getAlias('@nystudio107/codeeditor/config.php', false); | ||
| 48 |             if ($path === false || !file_exists($path)) { | ||
| 49 | return []; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | // Make sure we got a config file | ||
| 53 |         if (!is_array($config = @include $path)) { | ||
| 54 | return []; | ||
| 55 | } | ||
| 56 | // If it's not a multi-environment config, return the whole thing | ||
| 57 |         if (!array_key_exists('*', $config)) { | ||
| 58 | return $config; | ||
| 59 | } | ||
| 60 | // If no environment was specified, just look in the '*' array | ||
| 61 |         if ($currentEnv === null) { | ||
| 62 | return $config['*']; | ||
| 63 | } | ||
| 64 | $mergedConfig = []; | ||
| 65 |         foreach ($config as $env => $envConfig) { | ||
| 66 |             if ($env === '*' || StringHelper::contains($currentEnv, $env)) { | ||
| 67 | $mergedConfig = ArrayHelper::merge($mergedConfig, $envConfig); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | return $mergedConfig; | ||
| 72 | } | ||
| 74 |