Conditions | 12 |
Paths | 304 |
Total Lines | 79 |
Code Lines | 49 |
Lines | 24 |
Ratio | 30.38 % |
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 |
||
103 | public function run(IOutput $output) { |
||
104 | $isCoreUpdate = $this->isCoreUpdate(); |
||
105 | $appsToUpgrade = $this->getAppsToUpgrade(); |
||
106 | $failedCompatibleApps = []; |
||
107 | $failedMissingApps = $appsToUpgrade[self::KEY_MISSING]; |
||
108 | $failedIncompatibleApps = $appsToUpgrade[self::KEY_INCOMPATIBLE]; |
||
109 | $hasNotUpdatedCompatibleApps = 0; |
||
110 | $requiresMarketEnable = $this->requiresMarketEnable(); |
||
111 | |||
112 | if($isCoreUpdate && $requiresMarketEnable) { |
||
113 | // Then we need to enable the market app to support app updates / downloads during upgrade |
||
114 | $output->info('Enabling market app to assist with update'); |
||
115 | $this->appManager->enableApp('market'); |
||
116 | } |
||
117 | |||
118 | // Check if we can use the marketplace to update apps as needed? |
||
119 | if($this->appManager->isEnabledForUser('market')) { |
||
120 | // Use market to fix missing / old apps |
||
121 | $this->loadApp('market'); |
||
122 | $output->info('Using market to update existing apps'); |
||
123 | try { |
||
124 | // Try to update incompatible apps |
||
125 | View Code Duplication | if(!empty($appsToUpgrade[self::KEY_INCOMPATIBLE])) { |
|
|
|||
126 | $output->info('Attempting to update the following existing but incompatible app from market: '.implode(', ', $appsToUpgrade[self::KEY_INCOMPATIBLE])); |
||
127 | $failedIncompatibleApps = $this->getAppsFromMarket( |
||
128 | $output, |
||
129 | $appsToUpgrade[self::KEY_INCOMPATIBLE], |
||
130 | 'upgradeAppStoreApp' |
||
131 | ); |
||
132 | } |
||
133 | |||
134 | // Try to download missing apps |
||
135 | View Code Duplication | if(!empty($appsToUpgrade[self::KEY_MISSING])) { |
|
136 | $output->info('Attempting to update the following missing apps from market: '.implode(', ', $appsToUpgrade[self::KEY_MISSING])); |
||
137 | $failedMissingApps = $this->getAppsFromMarket( |
||
138 | $output, |
||
139 | $appsToUpgrade[self::KEY_MISSING], |
||
140 | 'reinstallAppStoreApp' |
||
141 | ); |
||
142 | } |
||
143 | |||
144 | // Try to update compatible apps |
||
145 | View Code Duplication | if(!empty($appsToUpgrade[self::KEY_COMPATIBLE])) { |
|
146 | $output->info('Attempting to update the following existing compatible apps from market: '.implode(', ', $appsToUpgrade[self::KEY_MISSING])); |
||
147 | $failedCompatibleApps = $this->getAppsFromMarket( |
||
148 | $output, |
||
149 | $appsToUpgrade[self::KEY_COMPATIBLE], |
||
150 | 'upgradeAppStoreApp' |
||
151 | ); |
||
152 | } |
||
153 | |||
154 | $hasNotUpdatedCompatibleApps = count($failedCompatibleApps); |
||
155 | } catch (AppManagerException $e) { |
||
156 | $output->warning('No connection to marketplace: ' . $e->getPrevious()); |
||
157 | } |
||
158 | } else { |
||
159 | // No market available, output error and continue attempt |
||
160 | $output->warning('Market app is unavailable for updating of apps. Enable with: occ:app:enable market'); |
||
161 | } |
||
162 | |||
163 | $hasBlockingMissingApps = count($failedMissingApps); |
||
164 | $hasBlockingIncompatibleApps = count($failedIncompatibleApps); |
||
165 | |||
166 | if ($hasBlockingIncompatibleApps || $hasBlockingMissingApps) { |
||
167 | // fail |
||
168 | $output->warning('You have incompatible or missing apps enabled that could not be found or updated via the marketplace.'); |
||
169 | $output->warning( |
||
170 | 'please install app manually with tarball or disable them with:' |
||
171 | . $this->getOccDisableMessage(array_merge($failedIncompatibleApps, $failedMissingApps)) |
||
172 | ); |
||
173 | |||
174 | throw new RepairException('Upgrade is not possible'); |
||
175 | } elseif ($hasNotUpdatedCompatibleApps) { |
||
176 | foreach ($failedCompatibleApps as $app) { |
||
177 | // TODO: Show reason |
||
178 | $output->info("App was not updated: $app"); |
||
179 | } |
||
180 | } |
||
181 | } |
||
182 | |||
274 |
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.