| Conditions | 11 |
| Paths | 6 |
| Total Lines | 37 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 | $strtolower = "strtolower"; |
||
| 73 | $strpos = "strpos"; |
||
| 74 | if (extension_loaded('mbstring')) { |
||
| 75 | $strtolower = "mb_strtolower"; |
||
| 76 | $strpos = "mb_strpos"; |
||
| 77 | } |
||
| 78 | $search = $strtolower(trim($this->name)); |
||
| 79 | $desc = $strtolower(trim($this->description)); |
||
| 80 | $ruleName = $this->ruleName; |
||
| 81 | foreach ($items as $name => $item) { |
||
| 82 | $f = (empty($search) || $strpos($strtolower($item->name), $search) !== false) && |
||
| 83 | (empty($desc) || $strpos($strtolower($item->description), $desc) !== false) && |
||
| 84 | (empty($ruleName) || $item->ruleName == $ruleName); |
||
| 85 | if (!$f) { |
||
| 86 | unset($items[$name]); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | return new ArrayDataProvider([ |
||
| 92 | 'allModels' => $items, |
||
| 93 | ]); |
||
| 94 | } |
||
| 95 | } |
||
| 96 |