| Conditions | 23 |
| Paths | > 20000 |
| Total Lines | 107 |
| Code Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 152 | private function getAppsForCategory($requestedCategory) { |
||
| 153 | $versionParser = new VersionParser(); |
||
| 154 | $formattedApps = []; |
||
| 155 | $apps = $this->appFetcher->get(); |
||
| 156 | foreach($apps as $app) { |
||
| 157 | if (isset($app['isFeatured'])) { |
||
| 158 | $app['featured'] = $app['isFeatured']; |
||
| 159 | } |
||
| 160 | |||
| 161 | // Skip all apps not in the requested category |
||
| 162 | $isInCategory = false; |
||
| 163 | foreach($app['categories'] as $category) { |
||
| 164 | if($category === $requestedCategory) { |
||
| 165 | $isInCategory = true; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | if(!$isInCategory) { |
||
| 169 | continue; |
||
| 170 | } |
||
| 171 | |||
| 172 | $nextCloudVersion = $versionParser->getVersion($app['releases'][0]['rawPlatformVersionSpec']); |
||
| 173 | $nextCloudVersionDependencies = []; |
||
| 174 | if($nextCloudVersion->getMinimumVersion() !== '') { |
||
| 175 | $nextCloudVersionDependencies['nextcloud']['@attributes']['min-version'] = $nextCloudVersion->getMinimumVersion(); |
||
| 176 | } |
||
| 177 | if($nextCloudVersion->getMaximumVersion() !== '') { |
||
| 178 | $nextCloudVersionDependencies['nextcloud']['@attributes']['max-version'] = $nextCloudVersion->getMaximumVersion(); |
||
| 179 | } |
||
| 180 | $phpVersion = $versionParser->getVersion($app['releases'][0]['rawPhpVersionSpec']); |
||
| 181 | $existsLocally = (\OC_App::getAppPath($app['id']) !== false) ? true : false; |
||
| 182 | $phpDependencies = []; |
||
| 183 | if($phpVersion->getMinimumVersion() !== '') { |
||
| 184 | $phpDependencies['php']['@attributes']['min-version'] = $phpVersion->getMinimumVersion(); |
||
| 185 | } |
||
| 186 | if($phpVersion->getMaximumVersion() !== '') { |
||
| 187 | $phpDependencies['php']['@attributes']['max-version'] = $phpVersion->getMaximumVersion(); |
||
| 188 | } |
||
| 189 | if(isset($app['releases'][0]['minIntSize'])) { |
||
| 190 | $phpDependencies['php']['@attributes']['min-int-size'] = $app['releases'][0]['minIntSize']; |
||
| 191 | } |
||
| 192 | $authors = ''; |
||
| 193 | foreach($app['authors'] as $key => $author) { |
||
| 194 | $authors .= $author['name']; |
||
| 195 | if($key !== count($app['authors']) - 1) { |
||
| 196 | $authors .= ', '; |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | $currentLanguage = substr(\OC::$server->getL10NFactory()->findLanguage(), 0, 2); |
||
| 201 | $enabledValue = $this->config->getAppValue($app['id'], 'enabled', 'no'); |
||
| 202 | $groups = null; |
||
| 203 | if($enabledValue !== 'no' && $enabledValue !== 'yes') { |
||
| 204 | $groups = $enabledValue; |
||
| 205 | } |
||
| 206 | |||
| 207 | $currentVersion = ''; |
||
| 208 | if($this->appManager->isInstalled($app['id'])) { |
||
| 209 | $currentVersion = \OC_App::getAppVersion($app['id']); |
||
| 210 | } else { |
||
| 211 | $currentLanguage = $app['releases'][0]['version']; |
||
| 212 | } |
||
| 213 | |||
| 214 | $formattedApps[] = [ |
||
| 215 | 'id' => $app['id'], |
||
| 216 | 'name' => isset($app['translations'][$currentLanguage]['name']) ? $app['translations'][$currentLanguage]['name'] : $app['translations']['en']['name'], |
||
| 217 | 'description' => isset($app['translations'][$currentLanguage]['description']) ? $app['translations'][$currentLanguage]['description'] : $app['translations']['en']['description'], |
||
| 218 | 'license' => $app['releases'][0]['licenses'], |
||
| 219 | 'author' => $authors, |
||
| 220 | 'shipped' => false, |
||
| 221 | 'version' => $currentVersion, |
||
| 222 | 'default_enable' => '', |
||
| 223 | 'types' => [], |
||
| 224 | 'documentation' => [ |
||
| 225 | 'admin' => $app['adminDocs'], |
||
| 226 | 'user' => $app['userDocs'], |
||
| 227 | 'developer' => $app['developerDocs'] |
||
| 228 | ], |
||
| 229 | 'website' => $app['website'], |
||
| 230 | 'bugs' => $app['issueTracker'], |
||
| 231 | 'detailpage' => $app['website'], |
||
| 232 | 'dependencies' => array_merge( |
||
| 233 | $nextCloudVersionDependencies, |
||
| 234 | $phpDependencies |
||
| 235 | ), |
||
| 236 | 'level' => ($app['featured'] === true) ? 200 : 100, |
||
| 237 | 'missingMaxOwnCloudVersion' => false, |
||
| 238 | 'missingMinOwnCloudVersion' => false, |
||
| 239 | 'canInstall' => true, |
||
| 240 | 'preview' => isset($app['screenshots'][0]['url']) ? 'https://usercontent.apps.nextcloud.com/'.base64_encode($app['screenshots'][0]['url']) : '', |
||
| 241 | 'score' => $app['ratingOverall'], |
||
| 242 | 'removable' => $existsLocally, |
||
| 243 | 'active' => $this->appManager->isEnabledForUser($app['id']), |
||
| 244 | 'needsDownload' => !$existsLocally, |
||
| 245 | 'groups' => $groups, |
||
| 246 | 'fromAppStore' => true, |
||
| 247 | ]; |
||
| 248 | |||
| 249 | |||
| 250 | $appFetcher = \OC::$server->getAppFetcher(); |
||
| 251 | $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher); |
||
| 252 | if($newVersion && $this->appManager->isInstalled($app['id'])) { |
||
|
|
|||
| 253 | $formattedApps[count($formattedApps)-1]['update'] = $newVersion; |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | return $formattedApps; |
||
| 258 | } |
||
| 259 | |||
| 352 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: