| Conditions | 12 |
| Paths | 157 |
| Total Lines | 82 |
| Code Lines | 51 |
| Lines | 24 |
| Ratio | 29.27 % |
| 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 |
||
| 111 | public function run(IOutput $output) { |
||
| 112 | |||
| 113 | if ($this->config->getSystemValue('has_internet_connection', true) !== true) { |
||
| 114 | $link = $this->defaults->buildDocLinkToKey('admin-marketplace-apps'); |
||
| 115 | $output->info('No internet connection available - no app updates will be taken from the marketplace.'); |
||
| 116 | $output->info("How to update apps in such situation please see $link"); |
||
| 117 | return; |
||
| 118 | } |
||
| 119 | $appsToUpgrade = $this->getAppsToUpgrade(); |
||
| 120 | $failedCompatibleApps = []; |
||
| 121 | $failedMissingApps = $appsToUpgrade[self::KEY_MISSING]; |
||
| 122 | $failedIncompatibleApps = $appsToUpgrade[self::KEY_INCOMPATIBLE]; |
||
| 123 | $hasNotUpdatedCompatibleApps = 0; |
||
| 124 | |||
| 125 | // fix market app state |
||
| 126 | $shallContactMarketplace = $this->fixMarketAppState($output); |
||
| 127 | if ($shallContactMarketplace) { |
||
| 128 | // Check if we can use the marketplace to update apps as needed? |
||
| 129 | if ($this->appManager->isEnabledForUser('market')) { |
||
| 130 | // Use market to fix missing / old apps |
||
| 131 | $this->loadApp('market'); |
||
| 132 | $output->info('Using market to update existing apps'); |
||
| 133 | try { |
||
| 134 | // Try to update incompatible apps |
||
| 135 | View Code Duplication | if (!empty($appsToUpgrade[self::KEY_INCOMPATIBLE])) { |
|
|
|
|||
| 136 | $output->info('Attempting to update the following existing but incompatible app from market: ' . implode(', ', $appsToUpgrade[self::KEY_INCOMPATIBLE])); |
||
| 137 | $failedIncompatibleApps = $this->getAppsFromMarket( |
||
| 138 | $output, |
||
| 139 | $appsToUpgrade[self::KEY_INCOMPATIBLE], |
||
| 140 | 'upgradeAppStoreApp' |
||
| 141 | ); |
||
| 142 | } |
||
| 143 | |||
| 144 | // Try to download missing apps |
||
| 145 | View Code Duplication | if (!empty($appsToUpgrade[self::KEY_MISSING])) { |
|
| 146 | $output->info('Attempting to update the following missing apps from market: ' . implode(', ', $appsToUpgrade[self::KEY_MISSING])); |
||
| 147 | $failedMissingApps = $this->getAppsFromMarket( |
||
| 148 | $output, |
||
| 149 | $appsToUpgrade[self::KEY_MISSING], |
||
| 150 | 'reinstallAppStoreApp' |
||
| 151 | ); |
||
| 152 | } |
||
| 153 | |||
| 154 | // Try to update compatible apps |
||
| 155 | View Code Duplication | if (!empty($appsToUpgrade[self::KEY_COMPATIBLE])) { |
|
| 156 | $output->info('Attempting to update the following existing compatible apps from market: ' . implode(', ', $appsToUpgrade[self::KEY_MISSING])); |
||
| 157 | $failedCompatibleApps = $this->getAppsFromMarket( |
||
| 158 | $output, |
||
| 159 | $appsToUpgrade[self::KEY_COMPATIBLE], |
||
| 160 | 'upgradeAppStoreApp' |
||
| 161 | ); |
||
| 162 | } |
||
| 163 | |||
| 164 | $hasNotUpdatedCompatibleApps = count($failedCompatibleApps); |
||
| 165 | } catch (AppManagerException $e) { |
||
| 166 | $output->warning('No connection to marketplace: ' . $e->getPrevious()); |
||
| 167 | } |
||
| 168 | } else { |
||
| 169 | // No market available, output error and continue attempt |
||
| 170 | $output->warning('Market app is unavailable for updating of apps. Enable with: occ app:enable market'); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | |||
| 174 | $hasBlockingMissingApps = count($failedMissingApps); |
||
| 175 | $hasBlockingIncompatibleApps = count($failedIncompatibleApps); |
||
| 176 | |||
| 177 | if ($hasBlockingIncompatibleApps || $hasBlockingMissingApps) { |
||
| 178 | // fail |
||
| 179 | $output->warning('You have incompatible or missing apps enabled that could not be found or updated via the marketplace.'); |
||
| 180 | $output->warning( |
||
| 181 | 'please install app manually with tarball or disable them with:' |
||
| 182 | . $this->getOccDisableMessage(array_merge($failedIncompatibleApps, $failedMissingApps)) |
||
| 183 | ); |
||
| 184 | |||
| 185 | throw new RepairException('Upgrade is not possible'); |
||
| 186 | } elseif ($hasNotUpdatedCompatibleApps) { |
||
| 187 | foreach ($failedCompatibleApps as $app) { |
||
| 188 | // TODO: Show reason |
||
| 189 | $output->info("App was not updated: $app"); |
||
| 190 | } |
||
| 191 | } |
||
| 192 | } |
||
| 193 | |||
| 323 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.