| Conditions | 12 |
| Paths | 12 |
| Total Lines | 42 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 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 |
||
| 46 | public function api($method) |
||
| 47 | { |
||
| 48 | switch ($method) { |
||
| 49 | case 'info': |
||
| 50 | $api = new Api\Info($this); |
||
| 51 | break; |
||
| 52 | case 'supported-languages': |
||
| 53 | $api = new Api\SupportedLanguages($this); |
||
| 54 | break; |
||
| 55 | case 'status': |
||
| 56 | $api = new Api\Status($this); |
||
| 57 | break; |
||
| 58 | case 'download': |
||
| 59 | $api = new Api\Download($this); |
||
| 60 | break; |
||
| 61 | case 'add-file': |
||
| 62 | $api = new Api\AddFile($this); |
||
| 63 | break; |
||
| 64 | case 'update-file': |
||
| 65 | $api = new Api\UpdateFile($this); |
||
| 66 | break; |
||
| 67 | case 'delete-file': |
||
| 68 | $api = new Api\DeleteFile($this); |
||
| 69 | break; |
||
| 70 | case 'export': |
||
| 71 | $api = new Api\Export($this); |
||
| 72 | break; |
||
| 73 | case 'add-directory': |
||
| 74 | $api = new Api\AddDirectory($this); |
||
| 75 | break; |
||
| 76 | case 'delete-directory': |
||
| 77 | $api = new Api\DeleteDirectory($this); |
||
| 78 | break; |
||
| 79 | case 'upload-translation': |
||
| 80 | $api = new Api\UploadTranslation($this); |
||
| 81 | break; |
||
| 82 | default: |
||
| 83 | throw new InvalidArgumentException(sprintf('Undefined api method "%s"', $method)); |
||
| 84 | } |
||
| 85 | |||
| 86 | return $api; |
||
| 87 | } |
||
| 88 | |||
| 117 |