| Conditions | 15 |
| Paths | 54 |
| Total Lines | 76 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 156 | public static function getPathToView($fileReference, bool $showHeaders = true, ?int $exeId = null, ?int $questionId = null, bool $isReadOnly = false): string |
||
| 157 | { |
||
| 158 | $plugin = OnlyofficePlugin::create(); |
||
| 159 | $appSettings = new OnlyofficeAppsettings($plugin); |
||
| 160 | $documentManager = new OnlyofficeDocumentManager($appSettings, []); |
||
| 161 | |||
| 162 | $isEnable = 'true' === $plugin->get('enable_onlyoffice_plugin'); |
||
| 163 | if (!$isEnable) { |
||
| 164 | return ''; |
||
| 165 | } |
||
| 166 | |||
| 167 | $urlToEdit = api_get_path(WEB_PLUGIN_PATH).'onlyoffice/editor.php'; |
||
| 168 | $queryString = $_SERVER['QUERY_STRING']; |
||
| 169 | $isExercise = str_contains($queryString, 'exerciseId='); |
||
| 170 | |||
| 171 | if (is_numeric($fileReference)) { |
||
| 172 | $documentId = (int) $fileReference; |
||
| 173 | $courseInfo = api_get_course_info(); |
||
| 174 | $sessionId = api_get_session_id(); |
||
| 175 | $userId = api_get_user_id(); |
||
| 176 | |||
| 177 | $docInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code'], false, $sessionId); |
||
| 178 | if (!$docInfo) { |
||
|
|
|||
| 179 | return ''; |
||
| 180 | } |
||
| 181 | |||
| 182 | $extension = strtolower(pathinfo($docInfo['path'], PATHINFO_EXTENSION)); |
||
| 183 | $canView = null !== $documentManager->getFormatInfo($extension) ? $documentManager->getFormatInfo($extension)->isViewable() : false; |
||
| 184 | |||
| 185 | $isGroupAccess = false; |
||
| 186 | $groupId = api_get_group_id(); |
||
| 187 | if (!empty($groupId)) { |
||
| 188 | $groupProperties = GroupManager::get_group_properties($groupId); |
||
| 189 | $docInfoGroup = api_get_item_property_info(api_get_course_int_id(), 'document', $documentId, $sessionId); |
||
| 190 | $isGroupAccess = GroupManager::allowUploadEditDocument($userId, $courseInfo['code'], $groupProperties, $docInfoGroup); |
||
| 191 | |||
| 192 | $urlToEdit.='?'.api_get_cidreq().'&'; |
||
| 193 | } else { |
||
| 194 | $urlToEdit.='?'.api_get_cidreq().'&'; |
||
| 195 | } |
||
| 196 | |||
| 197 | $isMyDir = DocumentManager::is_my_shared_folder($userId, $docInfo['absolute_parent_path'], $sessionId); |
||
| 198 | $accessRights = $isMyDir || $isGroupAccess; |
||
| 199 | |||
| 200 | $urlToEdit.='docId='.$documentId; |
||
| 201 | if (false === $showHeaders) { |
||
| 202 | $urlToEdit .= '&nh=1'; |
||
| 203 | } |
||
| 204 | |||
| 205 | if ($canView && !$accessRights) { |
||
| 206 | return $urlToEdit; |
||
| 207 | } |
||
| 208 | } else { |
||
| 209 | $urlToEdit .= '?'.$queryString.'&doc='.urlencode($fileReference); |
||
| 210 | if ($isExercise) { |
||
| 211 | $urlToEdit .= '&type=exercise'; |
||
| 212 | if ($exeId) { |
||
| 213 | $urlToEdit .= '&exeId=' . $exeId; |
||
| 214 | } |
||
| 215 | |||
| 216 | if ($questionId) { |
||
| 217 | $urlToEdit .= '&questionId=' . $questionId; |
||
| 218 | } |
||
| 219 | } |
||
| 220 | if (false === $showHeaders) { |
||
| 221 | $urlToEdit .= '&nh=1'; |
||
| 222 | } |
||
| 223 | |||
| 224 | if (true === $isReadOnly) { |
||
| 225 | $urlToEdit .= '&readOnly=1'; |
||
| 226 | } |
||
| 227 | |||
| 228 | return $urlToEdit; |
||
| 229 | } |
||
| 230 | |||
| 231 | return ''; |
||
| 232 | } |
||
| 234 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.