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

AdviceProcessor::callBack()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 12
rs 9.9666
cc 2
nc 2
nop 1
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\Advice\GetAdviceAction;
23
use Phalcon\Di\Injectable;
24
25
26
/**
27
 * Class AdviceProcessor
28
 *
29
 * @package MikoPBX\PBXCoreREST\Lib
30
 *
31
 * @property \MikoPBX\Common\Providers\MarketPlaceProvider license
32
 * @property \MikoPBX\Common\Providers\TranslationProvider translation
33
 * @property \Phalcon\Config config
34
 *
35
 */
36
class AdviceProcessor extends Injectable
37
{
38
    /**
39
     * Processes the Advice request.
40
     *
41
     * @param array $request The request data.
42
     *
43
     * @return PBXApiResult An object containing the result of the API call.
44
     */
45
    public static function callBack(array $request): PBXApiResult
46
    {
47
        $res = new PBXApiResult();
48
        $res->processor = __METHOD__;
49
        $action = $request['action'];
50
        if ('getList' === $action) {
51
            $res = GetAdviceAction::main();
52
        } else {
53
            $res->messages['error'][] = "Unknown action - $action in ".__CLASS__;
54
        }
55
        $res->function = $action;
56
        return $res;
57
    }
58
}