Conditions | 10 |
Paths | 10 |
Total Lines | 39 |
Code Lines | 25 |
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 |
||
26 | public function getValue($name) |
||
27 | { |
||
28 | switch ($name) { |
||
29 | case 'ThumbnailMIMEType': |
||
30 | switch ($this->MIMEType) { |
||
31 | case 'application/psd': |
||
32 | return 'image/png'; |
||
33 | case 'image/tiff': |
||
34 | return 'image/jpeg'; |
||
35 | default: |
||
36 | return $this->MIMEType; |
||
37 | } |
||
38 | |||
39 | // no break |
||
40 | case 'Extension': |
||
41 | |||
42 | switch ($this->MIMEType) { |
||
43 | case 'application/psd': |
||
44 | return 'psd'; |
||
45 | |||
46 | case 'image/tiff': |
||
47 | return 'tif'; |
||
48 | |||
49 | case 'image/gif': |
||
50 | return 'gif'; |
||
51 | |||
52 | case 'image/jpeg': |
||
53 | return 'jpg'; |
||
54 | |||
55 | case 'image/png': |
||
56 | return 'png'; |
||
57 | |||
58 | default: |
||
59 | throw new Exception('Unable to find photo extension for mime-type: '.$this->MIMEType); |
||
60 | } |
||
61 | |||
62 | // no break |
||
63 | default: |
||
64 | return parent::getValue($name); |
||
65 | } |
||
87 |