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