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