| Conditions | 23 |
| Paths | > 20000 |
| Total Lines | 129 |
| Code Lines | 78 |
| 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 |
||
| 104 | protected function convert(BackendUserAuthentication $user): array |
||
| 105 | { |
||
| 106 | // usergroups |
||
| 107 | $data = [ |
||
| 108 | 'user' => $user->user ?? [], |
||
| 109 | 'groups' => [ |
||
| 110 | 'inherit' => $user->userGroupsUID, |
||
| 111 | 'direct' => GeneralUtility::trimExplode(',', $user->user['usergroup'], true), |
||
| 112 | ], |
||
| 113 | 'modules' => [], |
||
| 114 | ]; |
||
| 115 | $data['groups']['diff'] = array_diff($data['groups']['inherit'], $data['groups']['direct']); |
||
| 116 | foreach ($data['groups'] as $type => $groups) { |
||
| 117 | foreach ($groups as $key => $id) { |
||
| 118 | $record = BackendUtility::getRecord('be_groups', (int)$id); |
||
| 119 | if ($record) { |
||
| 120 | $data['groups']['all'][$record['uid']]['row'] = $record; |
||
| 121 | $data['groups']['all'][$record['uid']][$type] = 1; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | // languages |
||
| 127 | $siteLanguages = $this->getAllSiteLanguages(); |
||
| 128 | $userLanguages = GeneralUtility::trimExplode(',', $user->groupData['allowed_languages'], true); |
||
| 129 | asort($userLanguages); |
||
| 130 | foreach ($userLanguages as $languageId) { |
||
| 131 | $languageId = (int)$languageId; |
||
| 132 | $record = $siteLanguages[$languageId]; |
||
| 133 | if ($record) { |
||
| 134 | $data['languages'][$languageId] = $record; |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | // table permissions |
||
| 139 | $data['tables']['tables_select'] = []; |
||
| 140 | $data['tables']['tables_modify'] = []; |
||
| 141 | foreach (['tables_select', 'tables_modify'] as $tableField) { |
||
| 142 | $temp = GeneralUtility::trimExplode(',', $user->groupData[$tableField], true); |
||
| 143 | foreach ($temp as $tableName) { |
||
| 144 | $data['tables'][$tableField][$tableName] = $GLOBALS['TCA'][$tableName]['ctrl']['title']; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | $data['tables']['all'] = array_replace($data['tables']['tables_select'] ?? [], $data['tables']['tables_modify'] ?? []); |
||
| 148 | |||
| 149 | // DB mounts |
||
| 150 | $dbMounts = GeneralUtility::trimExplode(',', $user->groupData['webmounts'], true); |
||
| 151 | asort($dbMounts); |
||
| 152 | foreach ($dbMounts as $mount) { |
||
| 153 | $record = BackendUtility::getRecord('pages', (int)$mount); |
||
| 154 | if ($record) { |
||
| 155 | $data['dbMounts'][] = $record; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | // File mounts |
||
| 160 | $fileMounts = GeneralUtility::trimExplode(',', $user->groupData['filemounts'], true); |
||
| 161 | asort($fileMounts); |
||
| 162 | foreach ($fileMounts as $mount) { |
||
| 163 | $record = BackendUtility::getRecord('sys_filemounts', (int)$mount); |
||
| 164 | if ($record) { |
||
| 165 | $data['fileMounts'][] = $record; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | // Modules |
||
| 170 | $modules = GeneralUtility::trimExplode(',', $user->groupData['modules'], true); |
||
| 171 | foreach ($modules as $module) { |
||
| 172 | $data['modules'][$module] = $GLOBALS['TBE_MODULES']['_configuration'][$module]; |
||
| 173 | } |
||
| 174 | $data['modules'] = array_filter($data['modules']); |
||
| 175 | |||
| 176 | // Categories |
||
| 177 | $categories = $user->getCategoryMountPoints(); |
||
| 178 | foreach ($categories as $category) { |
||
| 179 | $record = BackendUtility::getRecord('sys_category', $category); |
||
| 180 | if ($record) { |
||
| 181 | $data['categories'][$category] = $record; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | // workspaces |
||
| 186 | if (ExtensionManagementUtility::isLoaded('workspaces')) { |
||
| 187 | $data['workspaces'] = [ |
||
| 188 | 'loaded' => true, |
||
| 189 | 'record' => $user->workspaceRec |
||
| 190 | ]; |
||
| 191 | } |
||
| 192 | |||
| 193 | // file & folder permissions |
||
| 194 | if ($filePermissions = $user->groupData['file_permissions']) { |
||
| 195 | $items = GeneralUtility::trimExplode(',', $filePermissions, true); |
||
| 196 | foreach ($GLOBALS['TCA']['be_groups']['columns']['file_permissions']['config']['items'] as $availableItem) { |
||
| 197 | if (in_array($availableItem[1], $items, true)) { |
||
| 198 | $data['fileFolderPermissions'][] = $availableItem; |
||
| 199 | } |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | // tsconfig |
||
| 204 | $data['tsconfig'] = $user->getTSConfig(); |
||
| 205 | |||
| 206 | // non_exclude_fields |
||
| 207 | $fieldListTmp = GeneralUtility::trimExplode(',', $user->groupData['non_exclude_fields'], true); |
||
| 208 | $fieldList = []; |
||
| 209 | foreach ($fieldListTmp as $item) { |
||
| 210 | $split = explode(':', $item); |
||
| 211 | $fieldList[$split[0]]['label'] = $GLOBALS['TCA'][$split[0]]['ctrl']['title']; |
||
| 212 | $fieldList[$split[0]]['fields'][$split[1]] = $GLOBALS['TCA'][$split[0]]['columns'][$split[1]]['label'] ?? $split[1]; |
||
| 213 | } |
||
| 214 | ksort($fieldList); |
||
| 215 | foreach ($fieldList as &$fieldListItem) { |
||
| 216 | ksort($fieldListItem['fields']); |
||
| 217 | } |
||
| 218 | $data['non_exclude_fields'] = $fieldList; |
||
| 219 | |||
| 220 | // page types |
||
| 221 | $specialItems = $GLOBALS['TCA']['pages']['columns']['doktype']['config']['items']; |
||
| 222 | foreach ($specialItems as $specialItem) { |
||
| 223 | $value = $specialItem[1]; |
||
| 224 | if (!GeneralUtility::inList($user->groupData['pagetypes_select'], $value)) { |
||
| 225 | continue; |
||
| 226 | } |
||
| 227 | $label = $specialItem[0]; |
||
| 228 | $icon = $this->iconFactory->mapRecordTypeToIconIdentifier('pages', ['doktype' => $specialItem[1]]); |
||
| 229 | $data['pageTypes'][] = ['label' => $label, 'value' => $value, 'icon' => $icon]; |
||
| 230 | } |
||
| 231 | |||
| 232 | return $data; |
||
| 233 | } |
||
| 261 |