| Conditions | 10 |
| Paths | 24 |
| Total Lines | 42 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 56 | public function getAccessRights() |
||
| 57 | { |
||
| 58 | $isAllowToEdit = api_is_allowed_to_edit(true, true); |
||
| 59 | $isMyDir = DocumentManager::is_my_shared_folder( |
||
| 60 | api_get_user_id(), |
||
| 61 | $this->documentManager->getDocInfo('absolute_parent_path'), |
||
| 62 | api_get_session_id() |
||
| 63 | ); |
||
| 64 | $isGroupAccess = false; |
||
| 65 | if (!empty($this->documentManager->getGroupId())) { |
||
| 66 | $groupProperties = GroupManager::get_group_properties($this->documentManager->getGroupId()); |
||
| 67 | $docInfoGroup = api_get_item_property_info( |
||
| 68 | api_get_course_int_id(), |
||
| 69 | 'document', |
||
| 70 | $docId, |
||
| 71 | $sessionId |
||
| 72 | ); |
||
| 73 | $isGroupAccess = GroupManager::allowUploadEditDocument( |
||
| 74 | $userId, |
||
| 75 | $courseCode, |
||
| 76 | $groupProperties, |
||
| 77 | $docInfoGroup |
||
| 78 | ); |
||
| 79 | $isMemberGroup = GroupManager::is_user_in_group($userId, $groupProperties); |
||
| 80 | if (!$isGroupAccess) { |
||
| 81 | if (!$groupProperties['status']) { |
||
| 82 | api_not_allowed(true); |
||
| 83 | } |
||
| 84 | if (!$isMemberGroup && 1 != $groupProperties['doc_state']) { |
||
| 85 | api_not_allowed(true); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | // Allow editing if the document is part of an exercise |
||
| 91 | if (!empty($_GET['exerciseId']) || !empty($_GET['exeId'])) { |
||
| 92 | return true; |
||
| 93 | } |
||
| 94 | |||
| 95 | $accessRights = $isAllowToEdit || $isMyDir || $isGroupAccess; |
||
| 96 | |||
| 97 | return $accessRights; |
||
| 98 | } |
||
| 180 |