| Conditions | 18 |
| Paths | 100 |
| Total Lines | 51 |
| Code 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 |
||
| 95 | protected function isActive($action) |
||
| 96 | { |
||
| 97 | $uniqueId = $action->getUniqueId(); |
||
| 98 | if ($uniqueId === Yii::$app->getErrorHandler()->errorAction) { |
||
| 99 | return false; |
||
| 100 | } |
||
| 101 | |||
| 102 | $user = $this->getUser(); |
||
| 103 | if($user->getIsGuest()) |
||
| 104 | { |
||
| 105 | $loginUrl = null; |
||
| 106 | if(is_array($user->loginUrl) && isset($user->loginUrl[0])){ |
||
| 107 | $loginUrl = $user->loginUrl[0]; |
||
| 108 | }else if(is_string($user->loginUrl)){ |
||
| 109 | $loginUrl = $user->loginUrl; |
||
| 110 | } |
||
| 111 | if(!is_null($loginUrl) && trim($loginUrl,'/') === $uniqueId) |
||
| 112 | { |
||
| 113 | return false; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($this->owner instanceof Module) { |
||
| 118 | // convert action uniqueId into an ID relative to the module |
||
| 119 | $mid = $this->owner->getUniqueId(); |
||
| 120 | $id = $uniqueId; |
||
| 121 | if ($mid !== '' && strpos($id, $mid . '/') === 0) { |
||
| 122 | $id = substr($id, strlen($mid) + 1); |
||
| 123 | } |
||
| 124 | } else { |
||
| 125 | $id = $action->id; |
||
| 126 | } |
||
| 127 | |||
| 128 | foreach ($this->allowActions as $route) { |
||
| 129 | if (substr($route, -1) === '*') { |
||
| 130 | $route = rtrim($route, "*"); |
||
| 131 | if ($route === '' || strpos($id, $route) === 0) { |
||
| 132 | return false; |
||
| 133 | } |
||
| 134 | } else { |
||
| 135 | if ($id === $route) { |
||
| 136 | return false; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | if ($action->controller->hasMethod('allowAction') && in_array($action->id, $action->controller->allowAction())) { |
||
| 142 | return false; |
||
| 143 | } |
||
| 144 | |||
| 145 | return true; |
||
| 146 | } |
||
| 148 |