| Conditions | 15 |
| Paths | 34 |
| Total Lines | 40 |
| Code Lines | 17 |
| 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 |
||
| 40 | public function canView($member, $content = []) |
||
|
|
|||
| 41 | { |
||
| 42 | $owner = $this->getOwner(); |
||
| 43 | if (! $member) { |
||
| 44 | $member = Security::getCurrentUser(); |
||
| 45 | } |
||
| 46 | |||
| 47 | // admin override |
||
| 48 | if ($member && Permission::checkMember($member, ['ADMIN', 'SITETREE_VIEW_ALL'])) { |
||
| 49 | return true; |
||
| 50 | } |
||
| 51 | |||
| 52 | // if there is no meaningfull response go back to actual element itself! |
||
| 53 | if (! $owner->CanViewType || InheritedPermissions::ANYONE === $owner->CanViewType) { |
||
| 54 | return null; |
||
| 55 | } |
||
| 56 | |||
| 57 | // check for any NOT logged-in users |
||
| 58 | if (self::NOT_LOGGED_IN_USERS === $owner->CanViewType) { |
||
| 59 | if ($member && $member->ID) { |
||
| 60 | return false; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | // check for any logged-in users |
||
| 65 | if (InheritedPermissions::LOGGED_IN_USERS === $owner->CanViewType) { |
||
| 66 | if (! ($member && $member->ID)) { |
||
| 67 | return false; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | // check for specific groups |
||
| 72 | if (InheritedPermissions::ONLY_THESE_USERS === $owner->CanViewType) { |
||
| 73 | if (! ($member && $member->inGroups($owner->ViewerGroups()))) { |
||
| 74 | return false; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | //important - return back to actual element |
||
| 79 | return null; |
||
| 80 | } |
||
| 136 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.