| Conditions | 3 |
| Paths | 4 |
| Total Lines | 54 |
| Code Lines | 45 |
| Lines | 5 |
| Ratio | 9.26 % |
| 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 |
||
| 88 | public function getForm() { |
||
| 89 | $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
||
| 90 | $lookupServerUploadEnabled = false; |
||
| 91 | if($federatedFileSharingEnabled) { |
||
| 92 | $federatedFileSharing = new Application(); |
||
| 93 | $shareProvider = $federatedFileSharing->getFederatedShareProvider(); |
||
| 94 | $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
||
| 95 | } |
||
| 96 | |||
| 97 | $uid = \OC_User::getUser(); |
||
| 98 | $user = $this->userManager->get($uid); |
||
| 99 | $userData = $this->accountManager->getUser($user); |
||
|
|
|||
| 100 | |||
| 101 | $storageInfo = \OC_Helper::getStorageInfo('/'); |
||
| 102 | View Code Duplication | if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
| 103 | $totalSpace = $this->l->t('Unlimited'); |
||
| 104 | } else { |
||
| 105 | $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
||
| 106 | } |
||
| 107 | |||
| 108 | $languageParameters = $this->getLanguages($user); |
||
| 109 | $messageParameters = $this->getMessageParameters($userData); |
||
| 110 | |||
| 111 | $parameters = [ |
||
| 112 | 'total_space' => $totalSpace, |
||
| 113 | 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
||
| 114 | 'usage_relative' => round($storageInfo['relative']), |
||
| 115 | 'quota' => $storageInfo['quota'], |
||
| 116 | 'avatarChangeSupported' => $user->canChangeAvatar(), |
||
| 117 | 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
||
| 118 | 'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
||
| 119 | 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
||
| 120 | 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
||
| 121 | 'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'], |
||
| 122 | 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
||
| 123 | 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
||
| 124 | 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
||
| 125 | 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
||
| 126 | 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
||
| 127 | 'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
||
| 128 | 'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
||
| 129 | 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
||
| 130 | 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
||
| 131 | 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
||
| 132 | 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
||
| 133 | 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
||
| 134 | 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
||
| 135 | 'groups' => $this->getGroups($user), |
||
| 136 | 'passwordChangeSupported' => $user->canChangePassword(), |
||
| 137 | ] + $messageParameters + $languageParameters; |
||
| 138 | |||
| 139 | |||
| 140 | return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
||
| 141 | } |
||
| 142 | |||
| 245 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: