Passed
Push — develop ( 368e3d...115c7b )
by Nikolay
12:16
created

CdrDBProcessor::getActiveChannels()   C

Complexity

Conditions 12
Paths 18

Size

Total Lines 51
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 51
rs 6.9666
cc 12
nc 18
nop 0

How to fix   Long Method    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
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2023 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\CdrDB\GetActiveCallsAction;
23
use MikoPBX\PBXCoreREST\Lib\CdrDB\GetActiveChannelsAction;
24
use Phalcon\Di\Injectable;
25
26
/**
27
 * Class CdrDBProcessor
28
 *
29
 * @package MikoPBX\PBXCoreREST\Lib
30
 *
31
 */
32
class CdrDBProcessor extends Injectable
33
{
34
    /**
35
     * Processes CDR table requests
36
     *
37
     * @param array $request
38
     *
39
     * @return PBXApiResult An object containing the result of the API call.
40
     *
41
     */
42
    public static function callBack(array $request): PBXApiResult
43
    {
44
        $res = new PBXApiResult();
45
        $res->processor = __METHOD__;
46
        $action = $request['action'];
47
        switch ($action) {
48
            case 'getActiveChannels':
49
                $res = GetActiveChannelsAction::main();
50
                break;
51
            case 'getActiveCalls':
52
                $res = GetActiveCallsAction::main();
53
                break;
54
            default:
55
                $res->messages['error'][] = "Unknown action - $action in ".__CLASS__;
56
                break;
57
        }
58
        $res->function = $action;
59
        return $res;
60
    }
61
62
}