Conditions | 10 |
Paths | 55 |
Total Lines | 50 |
Code Lines | 33 |
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 |
||
34 | public function bootstrap($app) |
||
|
|||
35 | { |
||
36 | /** @var Module $module */ |
||
37 | /** @var \yii\db\ActiveRecord $modelName */ |
||
38 | if ($app->hasModule('activeuser') && ($module = $app->getModule('activeuser')) instanceof Module) { |
||
39 | $this->_modelMap = array_merge($this->_modelMap, $module->modelMap); |
||
40 | foreach ($this->_modelMap as $name => $definition) { |
||
41 | $class = "inblank\\activeuser\\models\\" . $name; |
||
42 | Yii::$container->set($class, $definition); |
||
43 | $modelName = is_array($definition) ? $definition['class'] : $definition; |
||
44 | $module->modelMap[$name] = $modelName; |
||
45 | } |
||
46 | if ($app instanceof ConsoleApplication) { |
||
47 | $app->controllerMap['activeuser'] = [ |
||
48 | 'class' => 'inblank\activeuser\commands\DefaultController', |
||
49 | ]; |
||
50 | } else { |
||
51 | // init user |
||
52 | Yii::$container->set('yii\web\User', [ |
||
53 | 'loginUrl' => ['/activeuser/account/login'], |
||
54 | 'identityClass' => self::di('User'), |
||
55 | ]); |
||
56 | $configUrlRule = [ |
||
57 | 'prefix' => $module->urlPrefix, |
||
58 | 'rules' => defined('IS_BACKEND') ? $module->urlRulesBackend : $module->urlRulesFrontend, |
||
59 | ]; |
||
60 | if ($module->urlPrefix != 'activeuser') { |
||
61 | $configUrlRule['routePrefix'] = 'activeuser'; |
||
62 | } |
||
63 | $app->urlManager->addRules([new GroupUrlRule($configUrlRule)], false); |
||
64 | if (defined('IS_BACKEND')) { |
||
65 | // is backend, and controller have other namespace |
||
66 | $module->controllerNamespace = 'inblank\activeuser\controllers\backend'; |
||
67 | $module->frontendUrlManager = new yii\web\UrlManager([ |
||
68 | 'baseUrl' => '/', |
||
69 | 'enablePrettyUrl' => true, |
||
70 | 'showScriptName' => false, |
||
71 | ]); |
||
72 | $configUrlRule['rules'] = $module->urlRulesFrontend; |
||
73 | $module->frontendUrlManager->addRules([new GroupUrlRule($configUrlRule)], false); |
||
74 | } |
||
75 | } |
||
76 | if (!isset($app->get('i18n')->translations['activeuser*'])) { |
||
77 | $app->get('i18n')->translations['activeuser*'] = [ |
||
78 | 'class' => PhpMessageSource::className(), |
||
79 | 'basePath' => __DIR__ . '/messages', |
||
80 | ]; |
||
81 | } |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 |