| Conditions | 5 |
| 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 |
||
| 68 | public function getAppList(string $newVersion): DataResponse { |
||
| 69 | if (!$this->config->getSystemValue('appstoreenabled', true)) { |
||
| 70 | return new DataResponse([ |
||
| 71 | 'appstore_disabled' => true, |
||
| 72 | ], Http::STATUS_NOT_FOUND); |
||
| 73 | } |
||
| 74 | |||
| 75 | // Get list of installed custom apps |
||
| 76 | $installedApps = $this->appManager->getInstalledApps(); |
||
| 77 | $installedApps = array_filter($installedApps, function($app) { |
||
| 78 | try { |
||
| 79 | $this->appManager->getAppPath($app); |
||
| 80 | } catch (AppPathNotFoundException $e) { |
||
| 81 | return false; |
||
| 82 | } |
||
| 83 | return !$this->appManager->isShipped($app); |
||
| 84 | }); |
||
| 85 | |||
| 86 | if (empty($installedApps)) { |
||
| 87 | return new DataResponse([ |
||
| 88 | 'missing' => [], |
||
| 89 | 'available' => [], |
||
| 90 | ]); |
||
| 91 | } |
||
| 92 | |||
| 93 | $this->appFetcher->setVersion($newVersion, 'future-apps.json'); |
||
| 94 | |||
| 95 | // Apps available on the app store for that version |
||
| 96 | $availableApps = array_map(function(array $app) { |
||
| 97 | return $app['id']; |
||
| 98 | }, $this->appFetcher->get()); |
||
| 99 | |||
| 100 | if (empty($availableApps)) { |
||
| 101 | return new DataResponse([ |
||
| 102 | 'appstore_disabled' => false, |
||
| 103 | 'already_on_latest' => false, |
||
| 104 | ], Http::STATUS_NOT_FOUND); |
||
| 105 | } |
||
| 106 | |||
| 107 | $missing = array_diff($installedApps, $availableApps); |
||
| 108 | $missing = array_map([$this, 'getAppDetails'], $missing); |
||
| 109 | sort($missing); |
||
| 110 | |||
| 111 | $available = array_intersect($installedApps, $availableApps); |
||
| 112 | $available = array_map([$this, 'getAppDetails'], $available); |
||
| 113 | sort($available); |
||
| 114 | |||
| 115 | return new DataResponse([ |
||
| 116 | 'missing' => $missing, |
||
| 117 | 'available' => $available, |
||
| 118 | ]); |
||
| 119 | } |
||
| 120 | |||
| 135 |