| Conditions | 15 |
| Paths | 23 |
| Total Lines | 59 |
| Code Lines | 40 |
| 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 |
||
| 92 | public function upgrade($oldversion) |
||
| 93 | { |
||
| 94 | $request = $this->container->get('request_stack')->getMasterRequest(); |
||
| 95 | // Upgrade dependent on old version number |
||
| 96 | switch ($oldversion) { |
||
| 97 | case '2.9.7': |
||
| 98 | case '2.9.8': |
||
|
|
|||
| 99 | $permasearch = $this->getSystemVar('permasearch'); |
||
| 100 | if (empty($permasearch)) { |
||
| 101 | $this->setSystemVar('permasearch', $this->__('À,Á,Â,Ã,Å,à,á,â,ã,å,Ò,Ó,Ô,Õ,Ø,ò,ó,ô,õ,ø,È,É,Ê,Ë,è,é,ê,ë,Ç,ç,Ì,Í,Î,Ï,ì,í,î,ï,Ù,Ú,Û,ù,ú,û,ÿ,Ñ,ñ,ß,ä,Ä,ö,Ö,ü,Ü')); |
||
| 102 | } |
||
| 103 | $permareplace = $this->getSystemVar('permareplace'); |
||
| 104 | if (empty($permareplace)) { |
||
| 105 | $this->setSystemVar('permareplace', $this->__('A,A,A,A,A,a,a,a,a,a,O,O,O,O,O,o,o,o,o,o,E,E,E,E,e,e,e,e,C,c,I,I,I,I,i,i,i,i,U,U,U,u,u,u,y,N,n,ss,ae,Ae,oe,Oe,ue,Ue')); |
||
| 106 | } |
||
| 107 | $locale = $this->getSystemVar('locale'); |
||
| 108 | if (empty($locale)) { |
||
| 109 | $this->setSystemVar('locale', $request->getLocale()); |
||
| 110 | } |
||
| 111 | |||
| 112 | case '2.9.9': |
||
| 113 | // update certain System vars to multilingual. provide default values for all locales using current value. |
||
| 114 | // must directly manipulate System vars at DB level because using $this->getSystemVar() returns empty values |
||
| 115 | $varsToChange = ['sitename', 'slogan', 'defaultpagetitle', 'defaultmetadescription']; |
||
| 116 | $SystemVars = $this->entityManager->getRepository('Zikula\ExtensionsModule\Entity\ExtensionVarEntity')->findBy(['modname' => VariableApi::CONFIG]); |
||
| 117 | /** @var \Zikula\ExtensionsModule\Entity\ExtensionVarEntity $modVar */ |
||
| 118 | foreach ($SystemVars as $modVar) { |
||
| 119 | if (in_array($modVar->getName(), $varsToChange)) { |
||
| 120 | foreach ($this->container->get('zikula_settings_module.locale_api')->getSupportedLocales() as $langcode) { |
||
| 121 | $newModVar = clone $modVar; |
||
| 122 | $newModVar->setName($modVar->getName() . '_' . $langcode); |
||
| 123 | $this->entityManager->persist($newModVar); |
||
| 124 | } |
||
| 125 | $this->entityManager->remove($modVar); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | $this->entityManager->flush(); |
||
| 129 | |||
| 130 | case '2.9.10': |
||
| 131 | $this->setSystemVar('startController', ''); |
||
| 132 | $newStargArgs = str_replace(',', '&', $this->getSystemVar('startargs')); // replace comma with `&` |
||
| 133 | $this->setSystemVar('startargs', $newStargArgs); |
||
| 134 | case '2.9.11': |
||
| 135 | $this->setSystemVar('useCompression', (bool)$this->getSystemVar('useCompression')); |
||
| 136 | case '2.9.12': // ship with Core-1.4.4 |
||
| 137 | // reconfigure TZ settings |
||
| 138 | $this->setGuestTimeZone(); |
||
| 139 | case '2.9.13': |
||
| 140 | $this->container->get('zikula_extensions_module.api.variable')->del(VariableApi::CONFIG, 'entrypoint'); |
||
| 141 | $this->container->get('zikula_extensions_module.api.variable')->del(VariableApi::CONFIG, 'shorturlsstripentrypoint'); |
||
| 142 | $this->container->get('zikula_extensions_module.api.variable')->del(VariableApi::CONFIG, 'shorturls'); |
||
| 143 | $this->container->get('zikula_extensions_module.api.variable')->del(VariableApi::CONFIG, 'shorturlsdefaultmodule'); |
||
| 144 | case '2.9.14': // ship with Core-1.5.0 |
||
| 145 | // current version |
||
| 146 | } |
||
| 147 | |||
| 148 | // Update successful |
||
| 149 | return true; |
||
| 150 | } |
||
| 151 | |||
| 196 |