Conditions | 11 |
Paths | 11 |
Total 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 |
||
163 | protected function reinitZipArchive() |
||
164 | { |
||
165 | $this->zipArchive = new ZipArchive(); |
||
166 | |||
167 | if (true !== ($resultCode = $this->zipArchive->open($this->zipFile, ZipArchive::CREATE))) { |
||
168 | switch ($resultCode) { |
||
169 | case ZipArchive::ER_EXISTS: |
||
170 | $errMsg = 'File already exists.'; |
||
171 | |||
172 | break; |
||
173 | case ZipArchive::ER_INCONS: |
||
174 | $errMsg = 'Zip archive inconsistent.'; |
||
175 | |||
176 | break; |
||
177 | case ZipArchive::ER_INVAL: |
||
178 | $errMsg = 'Invalid argument.'; |
||
179 | |||
180 | break; |
||
181 | case ZipArchive::ER_MEMORY: |
||
182 | $errMsg = 'Malloc failure.'; |
||
183 | |||
184 | break; |
||
185 | case ZipArchive::ER_NOENT: |
||
186 | $errMsg = 'Invalid argument.'; |
||
187 | |||
188 | break; |
||
189 | case ZipArchive::ER_NOZIP: |
||
190 | $errMsg = 'Not a zip archive.'; |
||
191 | |||
192 | break; |
||
193 | case ZipArchive::ER_OPEN: |
||
194 | $errMsg = 'Can\'t open file.'; |
||
195 | |||
196 | break; |
||
197 | case ZipArchive::ER_READ: |
||
198 | $errMsg = 'Read error.'; |
||
199 | |||
200 | break; |
||
201 | case ZipArchive::ER_SEEK: |
||
202 | $errMsg = 'Seek error.'; |
||
203 | |||
204 | break; |
||
205 | default: |
||
206 | $errMsg = 'Unknown error.'; |
||
207 | |||
208 | break; |
||
209 | } |
||
210 | |||
211 | throw new \RuntimeException(sprintf('%s', $errMsg)); |
||
212 | } |
||
213 | |||
214 | return $this; |
||
215 | } |
||
216 | |||
235 |