| Conditions | 13 |
| Paths | 24 |
| Total Lines | 34 |
| Code Lines | 19 |
| 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 |
||
| 32 | public static function changeModule($moduleId, $params = [], $merge = true) |
||
| 33 | { |
||
| 34 | if (empty(self::$config['modules'])) { |
||
| 35 | // create module field |
||
| 36 | self::$config['modules'] = []; |
||
| 37 | } |
||
| 38 | if (!empty(self::$config['modules'][$moduleId]) && $merge) { |
||
| 39 | // if we need merge configuration data |
||
| 40 | $currentParams = self::$config['modules'][$moduleId]; |
||
| 41 | if (is_string($currentParams)) { |
||
| 42 | $currentParams = [ |
||
| 43 | 'class' => $currentParams, |
||
| 44 | ]; |
||
| 45 | } |
||
| 46 | foreach ($params as $name => $value) { |
||
| 47 | $currentParams[$name] = $value; |
||
| 48 | } |
||
| 49 | $params = $currentParams; |
||
| 50 | } |
||
| 51 | self::$config['modules'][$moduleId] = $params; |
||
| 52 | // apply for current $app instance |
||
| 53 | $module = Yii::$app->getModule($moduleId); |
||
| 54 | if (!$merge || $module === null || (!empty($params['class']) && $module::className() != $params['class'])) { |
||
| 55 | // new or changed |
||
| 56 | Yii::$app->setModule($moduleId, $params); |
||
| 57 | } else { |
||
| 58 | // change the attributes |
||
| 59 | foreach ($params as $name => $value) { |
||
| 60 | if ($name !== 'class' && $module->canSetProperty($name)) { |
||
| 61 | $module->$name = $value; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 |