| Conditions | 6 |
| Paths | 9 |
| Total Lines | 76 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 75 | public function customEditorFileManager($parentId = 0): Response |
||
| 76 | { |
||
| 77 | $courseInfo = api_get_course_info(); |
||
| 78 | |||
| 79 | $params = [ |
||
| 80 | 'table' => '', |
||
| 81 | 'parent_id' => 0, |
||
| 82 | 'allow_course' => false, |
||
| 83 | ]; |
||
| 84 | |||
| 85 | if (!empty($courseInfo)) { |
||
| 86 | $groupIid = api_get_group_id(); |
||
| 87 | $isAllowedToEdit = api_is_allowed_to_edit(); |
||
| 88 | $groupMemberWithUploadRights = false; |
||
| 89 | |||
| 90 | $path = '/'; |
||
| 91 | if (!empty($parentId)) { |
||
| 92 | $doc = $this->getDoctrine()->getRepository('ChamiloCourseBundle:CDocument')->find($parentId); |
||
| 93 | $path = $doc->getPath(); |
||
| 94 | } |
||
| 95 | |||
| 96 | $documentAndFolders = DocumentManager::getAllDocumentData( |
||
| 97 | $courseInfo, |
||
| 98 | $path, |
||
| 99 | $groupIid, |
||
| 100 | null, |
||
| 101 | $isAllowedToEdit || $groupMemberWithUploadRights, |
||
| 102 | false, |
||
| 103 | 0, |
||
| 104 | null, |
||
| 105 | $parentId |
||
| 106 | ); |
||
| 107 | |||
| 108 | $url = $this->generateUrl('editor_filemanager', ['parentId' => $parentId]); |
||
| 109 | $data = DocumentManager::processDocumentAndFolders( |
||
| 110 | $documentAndFolders, |
||
| 111 | $courseInfo, |
||
| 112 | false, |
||
| 113 | $groupMemberWithUploadRights, |
||
| 114 | $path, |
||
| 115 | true, |
||
| 116 | $url |
||
| 117 | ); |
||
| 118 | |||
| 119 | $show = [1, 1, 1, 1]; |
||
| 120 | if ($isAllowedToEdit) { |
||
| 121 | $show = [0, 1, 1, 1, 1]; |
||
| 122 | } |
||
| 123 | |||
| 124 | $table = new \SortableTableFromArrayConfig( |
||
| 125 | $data, |
||
| 126 | 2, |
||
| 127 | 20, |
||
| 128 | 'documents', |
||
| 129 | $show, |
||
| 130 | [], |
||
| 131 | 'ASC', |
||
| 132 | true |
||
| 133 | ); |
||
| 134 | $column = 1; |
||
| 135 | if ($isAllowedToEdit) { |
||
| 136 | $table->set_header($column++, '', false, ['style' => 'width:12px;']); |
||
| 137 | } |
||
| 138 | $table->set_header($column++, get_lang('Type'), false, ['style' => 'width:30px;']); |
||
| 139 | $table->set_header($column++, get_lang('Name')); |
||
| 140 | $table->set_header($column++, get_lang('Size'), false, ['style' => 'width:50px;']); |
||
| 141 | $table->set_header($column, get_lang('Date'), false, ['style' => 'width:150px;']); |
||
| 142 | |||
| 143 | $params = [ |
||
| 144 | 'table' => $table->return_table(), |
||
| 145 | 'parent_id' => (int) $parentId, |
||
| 146 | 'allow_course' => true, |
||
| 147 | ]; |
||
| 148 | } |
||
| 149 | |||
| 150 | return $this->render('@ChamiloTheme/Editor/custom.html.twig', $params); |
||
| 151 | } |
||
| 228 |