| Conditions | 16 |
| Paths | 630 |
| Total Lines | 71 |
| Code Lines | 45 |
| 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 |
||
| 182 | public function executeCoreMetaUpgrade($currentCoreVersion): bool |
||
| 183 | { |
||
| 184 | $doctrine = $this->container->get('doctrine'); |
||
| 185 | /** |
||
| 186 | * NOTE: There are *intentionally* no `break` statements within each case here so that the process continues |
||
| 187 | * through each case until the end. |
||
| 188 | */ |
||
| 189 | switch ($currentCoreVersion) { |
||
| 190 | case '1.4.3': |
||
| 191 | $this->installModule('ZikulaMenuModule'); |
||
| 192 | $this->reSyncAndActivateModules(); |
||
| 193 | $this->setModuleCategory('ZikulaMenuModule', $this->translator->__('Content')); |
||
| 194 | case '1.4.4': |
||
| 195 | // nothing |
||
| 196 | case '1.4.5': |
||
| 197 | // Menu module was introduced in 1.4.4 but not installed on upgrade |
||
| 198 | $schemaManager = $doctrine->getConnection()->getSchemaManager(); |
||
| 199 | if (!$schemaManager->tablesExist(['menu_items'])) { |
||
| 200 | $this->installModule('ZikulaMenuModule'); |
||
| 201 | $this->reSyncAndActivateModules(); |
||
| 202 | $this->setModuleCategory('ZikulaMenuModule', $this->translator->__('Content')); |
||
| 203 | } |
||
| 204 | case '1.4.6': |
||
| 205 | // nothing needed |
||
| 206 | case '1.4.7': |
||
| 207 | // nothing needed |
||
| 208 | case '1.5.0': |
||
| 209 | // nothing needed |
||
| 210 | case '1.9.99': |
||
| 211 | // upgrades required for 2.0.0 |
||
| 212 | foreach (['objectdata_attributes', 'objectdata_log', 'objectdata_meta', 'workflows'] as $table) { |
||
| 213 | $sql = "DROP TABLE ${table};"; |
||
| 214 | /** @var \Doctrine\DBAL\Driver\PDOConnection $connection */ |
||
| 215 | $connection = $doctrine->getConnection(); |
||
| 216 | $stmt = $connection->prepare($sql); |
||
| 217 | $stmt->execute(); |
||
| 218 | $stmt->closeCursor(); |
||
| 219 | } |
||
| 220 | $variableApi = $this->container->get(VariableApi::class); |
||
| 221 | $variableApi->del(VariableApi::CONFIG, 'metakeywords'); |
||
| 222 | $variableApi->del(VariableApi::CONFIG, 'startpage'); |
||
| 223 | $variableApi->del(VariableApi::CONFIG, 'startfunc'); |
||
| 224 | $variableApi->del(VariableApi::CONFIG, 'starttype'); |
||
| 225 | if ('userdata' === $this->container->getParameter('datadir')) { |
||
| 226 | $this->yamlHelper->setParameter('datadir', 'web/uploads'); |
||
| 227 | $fs = $this->container->get('filesystem'); |
||
| 228 | $src = dirname(__DIR__, 5) . '/'; |
||
| 229 | try { |
||
| 230 | if ($fs->exists($src . '/userdata')) { |
||
| 231 | $fs->mirror($src . '/userdata', $src . '/web/uploads'); |
||
| 232 | } |
||
| 233 | } catch (\Exception $exception) { |
||
| 234 | $this->container->get('session')->getFlashBag()->add('info', $this->translator->__('Attempt to copy files from `userdata` to `web/uploads` failed. You must manually copy the contents.')); |
||
| 235 | } |
||
| 236 | } |
||
| 237 | // remove legacy blocks |
||
| 238 | $blocksToRemove = $doctrine->getRepository(BlockEntity::class)->findBy(['blocktype' => ['Extmenu', 'Menutree', 'Menu']]); |
||
| 239 | foreach ($blocksToRemove as $block) { |
||
| 240 | $doctrine->getManager()->remove($block); |
||
| 241 | } |
||
| 242 | $doctrine->getManager()->flush(); |
||
| 243 | case '2.0.0': |
||
| 244 | // nothing needed |
||
| 245 | case '3.0.0': |
||
| 246 | // current version - cannot perform anything yet |
||
| 247 | } |
||
| 248 | |||
| 249 | // always do this |
||
| 250 | $this->reSyncAndActivateModules(); |
||
| 251 | |||
| 252 | return true; |
||
| 253 | } |
||
| 255 |