| Conditions | 14 |
| Paths | 22 |
| Total Lines | 56 |
| Code Lines | 37 |
| 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 |
||
| 102 | public function upgrade($oldversion) |
||
| 103 | { |
||
| 104 | $request = $this->container->get('request_stack')->getMasterRequest(); |
||
| 105 | // Upgrade dependent on old version number |
||
| 106 | switch ($oldversion) { |
||
| 107 | case '2.9.7': |
||
| 108 | case '2.9.8': |
||
|
|
|||
| 109 | $permasearch = $this->getSystemVar('permasearch'); |
||
| 110 | if (empty($permasearch)) { |
||
| 111 | $this->setSystemVar('permasearch', $this->__('À,Á,Â,Ã,Å,à,á,â,ã,å,Ò,Ó,Ô,Õ,Ø,ò,ó,ô,õ,ø,È,É,Ê,Ë,è,é,ê,ë,Ç,ç,Ì,Í,Î,Ï,ì,í,î,ï,Ù,Ú,Û,ù,ú,û,ÿ,Ñ,ñ,ß,ä,Ä,ö,Ö,ü,Ü')); |
||
| 112 | } |
||
| 113 | $permareplace = $this->getSystemVar('permareplace'); |
||
| 114 | if (empty($permareplace)) { |
||
| 115 | $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')); |
||
| 116 | } |
||
| 117 | $locale = $this->getSystemVar('locale'); |
||
| 118 | if (empty($locale)) { |
||
| 119 | $this->setSystemVar('locale', $request->getLocale()); |
||
| 120 | } |
||
| 121 | |||
| 122 | case '2.9.9': |
||
| 123 | // update certain System vars to multilingual. provide default values for all locales using current value. |
||
| 124 | // must directly manipulate System vars at DB level because using $this->getSystemVar() returns empty values |
||
| 125 | $varsToChange = ['sitename', 'slogan', 'metakeywords', 'defaultpagetitle', 'defaultmetadescription']; |
||
| 126 | $SystemVars = $this->entityManager->getRepository('Zikula\ExtensionsModule\Entity\ExtensionVarEntity')->findBy(['modname' => VariableApi::CONFIG]); |
||
| 127 | /** @var \Zikula\ExtensionsModule\Entity\ExtensionVarEntity $modVar */ |
||
| 128 | foreach ($SystemVars as $modVar) { |
||
| 129 | if (in_array($modVar->getName(), $varsToChange)) { |
||
| 130 | foreach ($this->container->get('zikula_settings_module.locale_api')->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 | |||
| 140 | case '2.9.10': |
||
| 141 | $this->setSystemVar('startController', ''); |
||
| 142 | $newStargArgs = str_replace(',', '&', $this->getSystemVar('startargs')); // replace comma with `&` |
||
| 143 | $this->setSystemVar('startargs', $newStargArgs); |
||
| 144 | case '2.9.11': |
||
| 145 | $this->setSystemVar('shorturls', (bool) $this->getSystemVar('shorturls')); |
||
| 146 | $this->setSystemVar('shorturlsstripentrypoint', (bool) $this->getSystemVar('shorturlsstripentrypoint')); |
||
| 147 | $this->setSystemVar('useCompression', (bool) $this->getSystemVar('useCompression')); |
||
| 148 | case '2.9.12': // ship with Core-1.4.4 |
||
| 149 | // reconfigure TZ settings |
||
| 150 | $this->setGuestTimeZone(); |
||
| 151 | case '2.9.13': // ship with Core-1.5.0 |
||
| 152 | // current version |
||
| 153 | } |
||
| 154 | |||
| 155 | // Update successful |
||
| 156 | return true; |
||
| 157 | } |
||
| 158 | |||
| 200 |