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