| Conditions | 14 |
| Paths | 100 |
| Total Lines | 41 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 3 | 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 |
||
| 62 | public function getRightLists($roleId = null) |
||
| 63 | { |
||
| 64 | $rules = []; |
||
| 65 | $currentRole = 'All'; |
||
| 66 | foreach ($this->getResources() as $resource) { |
||
| 67 | foreach ($this->getRoles() as $roleKey => $role) { |
||
| 68 | $rules[] = $this->getRules(new Resource($resource), new Role($role)); |
||
| 69 | if ($roleId === $roleKey) { |
||
| 70 | $currentRole = $role; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | $rights = []; |
||
| 76 | foreach ($rules as $rule) { |
||
| 77 | if (is_array($rule)) { |
||
| 78 | foreach ($rule['byPrivilegeId'] as $right => $typeAndAssert) { |
||
| 79 | if (!in_array($right, $rights)) { |
||
| 80 | $rights[] = $right; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | if ($roleId === null) { |
||
| 87 | return $rights; |
||
| 88 | } |
||
| 89 | |||
| 90 | $rightList = []; |
||
| 91 | foreach ($this->getResources() as $resource) { |
||
| 92 | foreach ($rights as $key => $right) { |
||
| 93 | if ($currentRole !== 'All' |
||
| 94 | && $this->isAllowed($currentRole, $resource, $right) && !in_array($right, $rightList) |
||
| 95 | ) { |
||
| 96 | $rightList[] = $right; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | return $rightList; |
||
| 102 | } |
||
| 103 | |||
| 135 |