| Conditions | 8 |
| Paths | 6 |
| Total Lines | 53 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 29 | final public static function get($storage = [], $setting = null, $defaultValue = false) |
||
| 30 | { |
||
| 31 | $setting = self::parseSetting($setting); |
||
| 32 | |||
| 33 | if (empty($setting) || empty($storage)) { |
||
| 34 | return $defaultValue; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * If $setting is an array, process it recursively. |
||
| 39 | */ |
||
| 40 | if (is_array($setting)) { |
||
| 41 | /** |
||
| 42 | * Check if we have the first $setting element in the |
||
| 43 | * configuration data array. |
||
| 44 | */ |
||
| 45 | if (array_key_exists(0, $setting) && array_key_exists($setting[0], $storage)) { |
||
| 46 | /** |
||
| 47 | * Remove first element from $setting. |
||
| 48 | */ |
||
| 49 | $key = array_shift($setting); |
||
| 50 | /** |
||
| 51 | * At the end of the recursion $setting will be |
||
| 52 | * an empty array. In this case we simply return the |
||
| 53 | * current configuration data. |
||
| 54 | */ |
||
| 55 | if (empty($setting)) { |
||
| 56 | return $storage[$key]; |
||
| 57 | } |
||
| 58 | /** |
||
| 59 | * Go down one lement in the configuration data |
||
| 60 | * and call the method again, with the remainig setting. |
||
| 61 | */ |
||
| 62 | return self::get($storage[$key], $setting, $defaultValue); |
||
| 63 | } |
||
| 64 | /** |
||
| 65 | * The requested setting doesn't exist in our |
||
| 66 | * configuration data array. |
||
| 67 | */ |
||
| 68 | return $defaultValue; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * If we arrive here, $setting must be a simple string. |
||
| 73 | */ |
||
| 74 | if (array_key_exists($setting, $storage)) { |
||
| 75 | return $storage[$setting]; |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * If we got this far, there is no data to return. |
||
| 80 | */ |
||
| 81 | return $defaultValue; |
||
| 82 | } |
||
| 138 |