UEditorAction::handleAction()   B
last analyzed

Complexity

Conditions 10
Paths 13

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 7.6666
c 0
b 0
f 0
cc 10
nc 13
nop 0

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
4
namespace zacksleo\yii2\cms\actions;
5
6
use yii;
7
8
class UEditorAction extends \kucha\ueditor\UEditorAction
9
{
10
    /**
11
     * 处理action
12
     */
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