| Conditions | 10 |
| Paths | 4 |
| Total Lines | 29 |
| 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 |
||
| 58 | public function search($params) |
||
| 59 | { |
||
| 60 | /* @var \yii\rbac\Manager $authManager */ |
||
| 61 | $authManager = Configs::authManager(); |
||
| 62 | if ($this->type == Item::TYPE_ROLE) { |
||
| 63 | $items = $authManager->getRoles(); |
||
| 64 | } else { |
||
| 65 | $items = array_filter($authManager->getPermissions(), function($item) { |
||
| 66 | return $this->type == Item::TYPE_PERMISSION xor strncmp($item->name, '/', 1) === 0; |
||
| 67 | }); |
||
| 68 | } |
||
| 69 | $this->load($params); |
||
| 70 | if ($this->validate()) { |
||
| 71 | |||
| 72 | $search = mb_strtolower(trim($this->name)); |
||
| 73 | $desc = mb_strtolower(trim($this->description)); |
||
| 74 | $ruleName = $this->ruleName; |
||
| 75 | foreach ($items as $name => $item) { |
||
| 76 | $f = (empty($search) || mb_strpos(mb_strtolower($item->name), $search) !== false) && |
||
| 77 | (empty($desc) || mb_strpos(mb_strtolower($item->description), $desc) !== false) && |
||
| 78 | (empty($ruleName) || $item->ruleName == $ruleName); |
||
| 79 | if (!$f) { |
||
| 80 | unset($items[$name]); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | return new ArrayDataProvider([ |
||
| 86 | 'allModels' => $items, |
||
| 87 | ]); |
||
| 90 |