| Conditions | 6 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 34 |
| 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 |
||
| 92 | public function getAppList(string $newVersion): DataResponse { |
||
| 93 | if (!$this->config->getSystemValue('appstoreenabled', true)) { |
||
| 94 | return new DataResponse([ |
||
| 95 | 'appstore_disabled' => true, |
||
| 96 | ], Http::STATUS_NOT_FOUND); |
||
| 97 | } |
||
| 98 | |||
| 99 | // Get list of installed custom apps |
||
| 100 | $installedApps = $this->appManager->getInstalledApps(); |
||
| 101 | $installedApps = array_filter($installedApps, function ($app) { |
||
| 102 | try { |
||
| 103 | $this->appManager->getAppPath($app); |
||
| 104 | } catch (AppPathNotFoundException $e) { |
||
| 105 | return false; |
||
| 106 | } |
||
| 107 | return !$this->appManager->isShipped($app) && !isset($this->appsShippedInFutureVersion[$app]); |
||
| 108 | }); |
||
| 109 | |||
| 110 | if (empty($installedApps)) { |
||
| 111 | return new DataResponse([ |
||
| 112 | 'missing' => [], |
||
| 113 | 'available' => [], |
||
| 114 | ]); |
||
| 115 | } |
||
| 116 | |||
| 117 | $this->appFetcher->setVersion($newVersion, 'future-apps.json', false); |
||
| 118 | |||
| 119 | // Apps available on the app store for that version |
||
| 120 | $availableApps = array_map(static function (array $app) { |
||
| 121 | return $app['id']; |
||
| 122 | }, $this->appFetcher->get()); |
||
| 123 | |||
| 124 | if (empty($availableApps)) { |
||
| 125 | return new DataResponse([ |
||
| 126 | 'appstore_disabled' => false, |
||
| 127 | 'already_on_latest' => false, |
||
| 128 | ], Http::STATUS_NOT_FOUND); |
||
| 129 | } |
||
| 130 | |||
| 131 | $this->language = $this->l10nFactory->getUserLanguage($this->userSession->getUser()); |
||
| 132 | |||
| 133 | $missing = array_diff($installedApps, $availableApps); |
||
| 134 | $missing = array_map([$this, 'getAppDetails'], $missing); |
||
| 135 | sort($missing); |
||
| 136 | |||
| 137 | $available = array_intersect($installedApps, $availableApps); |
||
| 138 | $available = array_map([$this, 'getAppDetails'], $available); |
||
| 139 | sort($available); |
||
| 140 | |||
| 141 | return new DataResponse([ |
||
| 142 | 'missing' => $missing, |
||
| 143 | 'available' => $available, |
||
| 144 | ]); |
||
| 161 |