Conditions | 11 |
Paths | 6 |
Total Lines | 30 |
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 |
||
60 | public function getIsAdmin() |
||
61 | { |
||
62 | if ($this->_isAdmin === null) { |
||
63 | if ($this->getIsConsoleRequest() && !$this->forceWebRequest && !Yii::$app->hasModule('admin')) { |
||
64 | $this->_isAdmin = false; |
||
65 | } else { |
||
66 | // if there is only an application with admin module and set as default route |
||
67 | // this might by the admin module even when pathInfo is empty |
||
68 | if (Yii::$app->defaultRoute == 'admin' && empty($this->pathInfo)) { |
||
69 | $this->_isAdmin = true; |
||
70 | } else { |
||
71 | $resolver = Yii::$app->composition->getResolvedPathInfo($this); |
||
72 | $parts = explode('/', $resolver->resolvedPath); |
||
73 | $first = reset($parts); |
||
74 | |||
75 | // Check for a full route path where the module ends with admin like `newsadmin` and this module is loaded in the list of modules. |
||
76 | // @see https://github.com/luyadev/luya/pull/2027 |
||
77 | if (count($parts) > 0 && StringHelper::endsWith($first, 'admin') && Yii::$app->hasModule($first)) |
||
78 | $this->_isAdmin = true; |
||
79 | elseif (strtolower(trim($first)) == 'admin') { |
||
80 | $this->_isAdmin = true; |
||
81 | } else { |
||
82 | $this->_isAdmin = false; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | return $this->_isAdmin; |
||
89 | } |
||
90 | |||
102 |