Passed
Push — develop ( c8e8dc...cb2748 )
by Nikolay
06:11 queued 13s
created

FilesManagementProcessor::firmwareDownloadStatus()   B

Complexity

Conditions 8
Paths 24

Size

Total Lines 52
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 52
rs 8.0355
c 0
b 0
f 0
cc 8
nc 24
nop 1

How to fix   Long Method   

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
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2024 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
namespace MikoPBX\PBXCoreREST\Lib;
21
22
use MikoPBX\PBXCoreREST\Lib\Files\DownloadNewFirmware;
23
use MikoPBX\PBXCoreREST\Lib\Files\FirmwareDownloadStatus;
24
use MikoPBX\PBXCoreREST\Lib\Files\GetFileContent;
25
use MikoPBX\PBXCoreREST\Lib\Files\RemoveAudioFile;
26
use MikoPBX\PBXCoreREST\Lib\Files\StatusUploadFile;
27
use MikoPBX\PBXCoreREST\Lib\Files\UploadFile;
28
use Phalcon\Di\Injectable;
29
30
/**
31
 * Class FilesManagementProcessor
32
 *
33
 * @package MikoPBX\PBXCoreREST\Lib
34
 *
35
 */
36
class FilesManagementProcessor extends Injectable
37
{
38
39
    /**
40
     * Processes file upload requests
41
     *
42
     * @param array $request
43
     *
44
     * @return PBXApiResult An object containing the result of the API call.
45
     */
46
    public static function callBack(array $request): PBXApiResult
47
    {
48
        $res = new PBXApiResult();
49
        $res->processor = __METHOD__;
50
51
        $action = $request['action'];
52
        $postData = $request['data'];
53
        switch ($action) {
54
            case 'uploadFile':
55
                $res = UploadFile::main($postData);
56
                break;
57
            case 'statusUploadFile':
58
                $upload_id = $postData['id'] ?? '';
59
                $res = StatusUploadFile::main($upload_id);
60
                break;
61
            case 'removeAudioFile':
62
                $res = RemoveAudioFile::main($postData['filename']);
63
                break;
64
            case 'getFileContent':
65
                $res = GetFileContent::main($postData['filename'], $postData['needOriginal'] === 'true');
66
                break;
67
            case 'downloadNewFirmware':
68
                $res = DownloadNewFirmware::main($postData);
69
                break;
70
            case 'firmwareDownloadStatus':
71
                $res = FirmwareDownloadStatus::main($postData['filename']);
72
                break;
73
            default:
74
                $res->messages['error'][] = "Unknown action - $action in " . __CLASS__;
75
        }
76
77
        $res->function = $action;
78
79
        return $res;
80
    }
81
82
}