Conditions | 10 |
Paths | 13 |
Total Lines | 43 |
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 |
||
13 | protected function handleAction() |
||
14 | { |
||
15 | $action = Yii::$app->request->get('action'); |
||
16 | switch ($action) { |
||
17 | case 'config': |
||
18 | $result = $this->config; |
||
19 | break; |
||
20 | |||
21 | /* 上传图片 */ |
||
22 | case 'uploadimage': |
||
23 | /* 上传涂鸦 */ |
||
24 | case 'uploadscrawl': |
||
25 | /* 上传视频 */ |
||
26 | case 'uploadvideo': |
||
27 | /* 上传文件 */ |
||
28 | case 'uploadfile': |
||
29 | $result = $this->actionUpload(); |
||
30 | //处理返回的URL |
||
31 | if (substr($result['url'], 0, 1) != '/') { |
||
32 | $result['url'] = '/' . $result['url']; |
||
33 | } |
||
34 | break; |
||
35 | /* 列出图片 */ |
||
36 | case 'listimage': |
||
37 | /* 列出文件 */ |
||
38 | case 'listfile': |
||
39 | $result = $this->actionList(); |
||
40 | break; |
||
41 | |||
42 | /* 抓取远程文件 */ |
||
43 | case 'catchimage': |
||
44 | $result = $this->actionCrawler(); |
||
45 | break; |
||
46 | |||
47 | default: |
||
48 | $result = [ |
||
49 | 'state' => '请求地址出错' |
||
50 | ]; |
||
51 | break; |
||
52 | } |
||
53 | /* 输出结果 */ |
||
54 | return $result; |
||
55 | } |
||
56 | } |
||
57 |