Conditions | 14 |
Paths | 720 |
Total Lines | 65 |
Code Lines | 46 |
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 |
||
65 | public function upgrade(string $oldVersion): bool |
||
66 | { |
||
67 | // Upgrade dependent on old version number |
||
68 | switch ($oldVersion) { |
||
69 | case '1.3.1': |
||
70 | $this->setVar('smtpsecuremethod', 'ssl'); |
||
|
|||
71 | case '1.3.2': |
||
72 | // clear old modvars |
||
73 | // use manual method because getVars() is not available during system upgrade |
||
74 | $modVarEntities = $this->managerRegistry->getRepository(ExtensionVarEntity::class)->findBy(['modname' => $this->name]); |
||
75 | $modVars = []; |
||
76 | foreach ($modVarEntities as $var) { |
||
77 | $modVars[$var['name']] = $var['value']; |
||
78 | } |
||
79 | $this->delVars(); |
||
80 | $this->setVarWithDefault('charset', $modVars['charset']); |
||
81 | $this->setVarWithDefault('encoding', $modVars['encoding']); |
||
82 | $this->setVarWithDefault('html', $modVars['html']); |
||
83 | $this->setVarWithDefault('wordwrap', $modVars['wordwrap']); |
||
84 | // new modvar for 1.4.0 |
||
85 | $this->setVarWithDefault('enableLogging', false); |
||
86 | |||
87 | // write the config file |
||
88 | $mailerTypeConversion = [ |
||
89 | 1 => 'mail', |
||
90 | 2 => 'sendmail', |
||
91 | 3 => 'mail', |
||
92 | 4 => 'smtp', |
||
93 | 5 => 'mail', |
||
94 | ]; |
||
95 | $config = [ |
||
96 | 'transport' => $mailerTypeConversion[$modVars['mailertype']], |
||
97 | 'username' => $modVars['smtpusername'], |
||
98 | 'password' => $modVars['smtppassword'], |
||
99 | 'host' => $modVars['smtpserver'], |
||
100 | 'port' => $modVars['smtpport'], |
||
101 | 'encryption' => isset($modVars['smtpsecuremethod']) && in_array($modVars['smtpsecuremethod'], ['ssl', 'tls']) ? $modVars['smtpsecuremethod'] : 'ssl', |
||
102 | 'auth_mode' => !empty($modVars['auth']) ? 'login' : null, |
||
103 | 'spool' => ['type' => 'memory'], |
||
104 | 'delivery_addresses' => [], |
||
105 | 'disable_delivery' => 5 === $modVars['mailertype'], |
||
106 | ]; |
||
107 | $this->configDumper->setConfiguration('swiftmailer', $config); |
||
108 | case '1.4.0': |
||
109 | $config = $this->configDumper->getConfiguration('swiftmailer'); |
||
110 | // remove spool parameter |
||
111 | unset($config['spool']); |
||
112 | $this->configDumper->setConfiguration('swiftmailer', $config); |
||
113 | case '1.4.1': |
||
114 | // install subscriber hooks |
||
115 | case '1.4.2': |
||
116 | $config = $this->configDumper->getConfiguration('swiftmailer'); |
||
117 | // delivery_address has changed to an array named delivery_addresses |
||
118 | $config['delivery_addresses'] = !empty($config['delivery_address']) ? [$config['delivery_address']] : []; |
||
119 | unset($config['delivery_address']); |
||
120 | $this->configDumper->setConfiguration('swiftmailer', $config); |
||
121 | case '1.4.3': |
||
122 | // nothing |
||
123 | case '1.5.0': |
||
124 | case '1.5.1': |
||
125 | // future upgrade routines |
||
126 | } |
||
127 | |||
128 | // Update successful |
||
129 | return true; |
||
130 | } |
||
169 |