| Conditions | 19 |
| Paths | 3264 |
| Total Lines | 80 |
| Code Lines | 58 |
| 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 |
||
| 97 | public function upgrade(string $oldVersion): bool |
||
| 98 | { |
||
| 99 | $request = $this->requestStack->getMasterRequest(); |
||
| 100 | // Upgrade dependent on old version number |
||
| 101 | switch ($oldVersion) { |
||
| 102 | case '2.9.7': |
||
| 103 | case '2.9.8': |
||
| 104 | $permasearch = $this->getSystemVar('permasearch'); |
||
| 105 | if (empty($permasearch)) { |
||
| 106 | $this->setSystemVar('permasearch', $this->getDefaultValue('permasearch')); |
||
| 107 | } |
||
| 108 | $permareplace = $this->getSystemVar('permareplace'); |
||
| 109 | if (empty($permareplace)) { |
||
| 110 | $this->setSystemVar('permareplace', $this->getDefaultValue('permareplace')); |
||
| 111 | } |
||
| 112 | $locale = $this->getSystemVar('locale'); |
||
| 113 | if (empty($locale)) { |
||
|
|
|||
| 114 | $this->setSystemVar('locale', $request->getLocale()); |
||
| 115 | } |
||
| 116 | |||
| 117 | case '2.9.9': |
||
| 118 | // update certain System vars to multilingual. provide default values for all locales using current value. |
||
| 119 | // must directly manipulate System vars at DB level because using $this->getSystemVar() returns empty values |
||
| 120 | $varsToChange = [ |
||
| 121 | 'sitename', |
||
| 122 | 'slogan', |
||
| 123 | 'defaultpagetitle', |
||
| 124 | 'defaultmetadescription' |
||
| 125 | ]; |
||
| 126 | $systemVars = $this->managerRegistry->getRepository(ExtensionVarEntity::class)->findBy(['modname' => VariableApi::CONFIG]); |
||
| 127 | /** @var ExtensionVarEntity $modVar */ |
||
| 128 | foreach ($systemVars as $modVar) { |
||
| 129 | if (in_array($modVar->getName(), $varsToChange, true)) { |
||
| 130 | foreach ($this->localeApi->getSupportedLocales() as $langcode) { |
||
| 131 | $newModVar = clone $modVar; |
||
| 132 | $newModVar->setName($modVar->getName() . '_' . $langcode); |
||
| 133 | $this->entityManager->persist($newModVar); |
||
| 134 | } |
||
| 135 | $this->entityManager->remove($modVar); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | $this->entityManager->flush(); |
||
| 139 | case '2.9.10': |
||
| 140 | case '2.9.11': |
||
| 141 | $this->setSystemVar('UseCompression', (bool)$this->getSystemVar('UseCompression')); |
||
| 142 | case '2.9.12': // ship with Core-1.4.4 |
||
| 143 | // reconfigure TZ settings |
||
| 144 | $this->setGuestTimeZone(); |
||
| 145 | case '2.9.13': |
||
| 146 | $this->getVariableApi()->del(VariableApi::CONFIG, 'entrypoint'); |
||
| 147 | $this->getVariableApi()->del(VariableApi::CONFIG, 'shorturlsstripentrypoint'); |
||
| 148 | $this->getVariableApi()->del(VariableApi::CONFIG, 'shorturls'); |
||
| 149 | $this->getVariableApi()->del(VariableApi::CONFIG, 'shorturlsdefaultmodule'); |
||
| 150 | case '2.9.14': // ship with Core-1.5.0 + Core-2.x |
||
| 151 | $this->getVariableApi()->del(VariableApi::CONFIG, 'Version_Sub'); |
||
| 152 | $this->setSystemVar('startController'); // reset to blank because of new format FQCN::method |
||
| 153 | case '2.9.15': |
||
| 154 | $varsToRemove = [ |
||
| 155 | 'funtext', |
||
| 156 | 'reportlevel', |
||
| 157 | 'idnnames', |
||
| 158 | 'debug', |
||
| 159 | 'debug_sql', |
||
| 160 | 'useflags', |
||
| 161 | 'language_i18n', |
||
| 162 | 'startController', |
||
| 163 | 'startargs' |
||
| 164 | ]; |
||
| 165 | foreach ($varsToRemove as $varName) { |
||
| 166 | $this->getVariableApi()->del(VariableApi::CONFIG, $varName); |
||
| 167 | } |
||
| 168 | foreach ($this->localeApi->getSupportedLocales() as $lang) { |
||
| 169 | $this->setSystemVar('startController_' . $lang, $this->getDefaultValue('startController')); |
||
| 170 | } |
||
| 171 | case '2.9.16': // ship with Core-3.0.0 |
||
| 172 | // current version |
||
| 173 | } |
||
| 174 | |||
| 175 | // Update successful |
||
| 176 | return true; |
||
| 177 | } |
||
| 235 |