Conditions | 11 |
Paths | 20 |
Total Lines | 42 |
Code Lines | 20 |
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 |
||
43 | public static function getConfigFromFile(string $filePath, $alias = null): array |
||
44 | { |
||
45 | // Try craft/config first |
||
46 | $path = self::getConfigFilePath('@config', $filePath); |
||
47 | if (!file_exists($path)) { |
||
48 | // Now try our own internal config |
||
49 | $path = self::getConfigFilePath('@nystudio107/seomatic', $filePath); |
||
50 | if (!file_exists($path)) { |
||
51 | if (!$alias) { |
||
52 | return []; |
||
53 | } |
||
54 | // Now the additional alias config |
||
55 | $path = self::getConfigFilePath($alias, $filePath); |
||
56 | if (!file_exists($path)) { |
||
57 | return []; |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | |||
62 | if (!is_array($config = @include $path)) { |
||
63 | return []; |
||
64 | } |
||
65 | |||
66 | // If it's not a multi-environment config, return the whole thing |
||
67 | if (!array_key_exists('*', $config)) { |
||
68 | return $config; |
||
69 | } |
||
70 | |||
71 | // If no environment was specified, just look in the '*' array |
||
72 | if (empty(Seomatic::$environment)) { |
||
73 | return $config['*']; |
||
74 | } |
||
75 | |||
76 | $mergedConfig = []; |
||
77 | /** @var array $config */ |
||
78 | foreach ($config as $env => $envConfig) { |
||
79 | if ($env === '*' || StringHelper::contains(Seomatic::$environment, $env)) { |
||
80 | $mergedConfig = ArrayHelper::merge($mergedConfig, $envConfig); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | return $mergedConfig; |
||
85 | } |
||
127 |