Conditions | 18 |
Paths | 4352 |
Total Lines | 74 |
Code Lines | 53 |
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 |
||
98 | public function upgrade(string $oldVersion): bool |
||
99 | { |
||
100 | $request = $this->requestStack->getMasterRequest(); |
||
101 | // Upgrade dependent on old version number |
||
102 | switch ($oldVersion) { |
||
103 | case '2.9.7': |
||
104 | case '2.9.8': |
||
105 | $permasearch = $this->getSystemVar('permasearch'); |
||
106 | if (empty($permasearch)) { |
||
107 | $this->setSystemVar('permasearch', $this->trans('À,Á,Â,Ã,Å,à,á,â,ã,å,Ò,Ó,Ô,Õ,Ø,ò,ó,ô,õ,ø,È,É,Ê,Ë,è,é,ê,ë,Ç,ç,Ì,Í,Î,Ï,ì,í,î,ï,Ù,Ú,Û,ù,ú,û,ÿ,Ñ,ñ,ß,ä,Ä,ö,Ö,ü,Ü')); |
||
108 | } |
||
109 | $permareplace = $this->getSystemVar('permareplace'); |
||
110 | if (empty($permareplace)) { |
||
111 | $this->setSystemVar('permareplace', $this->trans('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')); |
||
112 | } |
||
113 | $locale = $this->getSystemVar('locale'); |
||
114 | if (empty($locale)) { |
||
|
|||
115 | $this->setSystemVar('locale', $request->getLocale()); |
||
116 | } |
||
117 | |||
118 | case '2.9.9': |
||
119 | // update certain System vars to multilingual. provide default values for all locales using current value. |
||
120 | // must directly manipulate System vars at DB level because using $this->getSystemVar() returns empty values |
||
121 | $varsToChange = ['sitename', 'slogan', 'defaultpagetitle', 'defaultmetadescription']; |
||
122 | $systemVars = $this->managerRegistry->getRepository(ExtensionVarEntity::class)->findBy(['modname' => VariableApi::CONFIG]); |
||
123 | /** @var ExtensionVarEntity $modVar */ |
||
124 | foreach ($systemVars as $modVar) { |
||
125 | if (in_array($modVar->getName(), $varsToChange, true)) { |
||
126 | foreach ($this->localeApi->getSupportedLocales() as $langcode) { |
||
127 | $newModVar = clone $modVar; |
||
128 | $newModVar->setName($modVar->getName() . '_' . $langcode); |
||
129 | $this->entityManager->persist($newModVar); |
||
130 | } |
||
131 | $this->entityManager->remove($modVar); |
||
132 | } |
||
133 | } |
||
134 | $this->entityManager->flush(); |
||
135 | |||
136 | case '2.9.10': |
||
137 | $this->setSystemVar('startController'); |
||
138 | $newStargArgs = str_replace(',', '&', $this->getSystemVar('startargs')); // replace comma with `&` |
||
139 | $this->setSystemVar('startargs', $newStargArgs); |
||
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 | ]; |
||
163 | foreach ($varsToRemove as $varName) { |
||
164 | $this->getVariableApi()->del(VariableApi::CONFIG, $varName); |
||
165 | } |
||
166 | case '2.9.16': // ship with Core-3.0.0 |
||
167 | // current version |
||
168 | } |
||
169 | |||
170 | // Update successful |
||
171 | return true; |
||
172 | } |
||
207 |