| Conditions | 15 |
| Paths | 5184 |
| Total Lines | 99 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 47 | public function getGroupInformation(int $groupId): array |
||
| 48 | { |
||
| 49 | $usergroupRecord = BackendUtility::getRecord('be_groups', $groupId); |
||
| 50 | if (!$usergroupRecord) { |
||
| 51 | return []; |
||
| 52 | } |
||
| 53 | |||
| 54 | $user = GeneralUtility::makeInstance(BackendUserAuthentication::class); |
||
| 55 | $user->enablecolumns = [ |
||
| 56 | 'deleted' => true |
||
| 57 | ]; |
||
| 58 | // Setup dummy user to allow fetching all group data |
||
| 59 | // @see \TYPO3\CMS\Core\Authentication\BackendUserAuthentication::fetchGroups |
||
| 60 | $user->user = [ |
||
| 61 | 'uid' => 3016, |
||
| 62 | 'options' => 3, |
||
| 63 | $user->usergroup_column => $groupId |
||
| 64 | ]; |
||
| 65 | $user->fetchGroupData(); |
||
| 66 | |||
| 67 | $data = $this->convert($user); |
||
| 68 | $data['group'] = $usergroupRecord; |
||
| 69 | |||
| 70 | return $data; |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Get all relevant information of the user |
||
| 75 | * |
||
| 76 | * @param int $userId |
||
| 77 | * @return array |
||
| 78 | */ |
||
| 79 | public function getUserInformation(int $userId): array |
||
| 80 | { |
||
| 81 | $user = GeneralUtility::makeInstance(BackendUserAuthentication::class); |
||
| 82 | $user->enablecolumns = [ |
||
| 83 | 'deleted' => true |
||
| 84 | ]; |
||
| 85 | $user->setBeUserByUid($userId); |
||
| 86 | if (!$user->user) { |
||
| 87 | return []; |
||
| 88 | } |
||
| 89 | $user->fetchGroupData(); |
||
| 90 | |||
| 91 | return $this->convert($user); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Convert hard readable user & group information into structured |
||
| 96 | * data which can be rendered later |
||
| 97 | * |
||
| 98 | * @param BackendUserAuthentication $user |
||
| 99 | * @return array |
||
| 100 | */ |
||
| 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) { |
||
| 229 |