Passed
Push — develop ( a6a975...49e3f5 )
by Nikolay
04:45 queued 13s
created

LicenseManagementProcessor::sendMetricsAction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 37
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 37
rs 9.7
cc 2
nc 2
nop 0
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\License\CaptureFeatureForProductIdAction;
23
use MikoPBX\PBXCoreREST\Lib\License\GetLicenseInfoAction;
24
use MikoPBX\PBXCoreREST\Lib\License\GetMikoPBXFeatureStatusAction;
25
use MikoPBX\PBXCoreREST\Lib\License\PingAction;
26
use MikoPBX\PBXCoreREST\Lib\License\ProcessUserRequestAction;
27
use MikoPBX\PBXCoreREST\Lib\License\ResetLicenseAction;
28
use MikoPBX\PBXCoreREST\Lib\License\SendMetricsAction;
29
use Phalcon\Di\Injectable;
30
use function MikoPBX\PBXCoreREST\Lib\License\ResetLicenseAction;
0 ignored issues
show
introduced by
The function MikoPBX\PBXCoreREST\Lib\License\ResetLicenseAction was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
32
/**
33
 * Class LicenseManagementProcessor
34
 *
35
 * @package MikoPBX\PBXCoreREST\Lib
36
 *
37
 */
38
class LicenseManagementProcessor extends Injectable
39
{
40
41
    /**
42
     * Process the license callback.
43
     *
44
     * @param array $request The request data.
45
     *
46
     * @return PBXApiResult An object containing the result of the API call.
47
     */
48
    public static function callBack(array $request): PBXApiResult
49
    {
50
        $action = $request['action'];
51
        $data = $request['data'];
52
        $res = new PBXApiResult();
53
        $res->processor = __METHOD__;
54
        switch ($action) {
55
            case 'resetKey':
56
                $res = ResetLicenseAction::main($data);
57
                break;
58
            case 'processUserRequest':
59
                $res = ProcessUserRequestAction::main($data);
60
                break;
61
            case 'getLicenseInfo':
62
                $res = GetLicenseInfoAction::main();
63
                break;
64
            case 'getMikoPBXFeatureStatus':
65
                $res = GetMikoPBXFeatureStatusAction::main();
66
                break;
67
            case 'captureFeatureForProductId':
68
                $res = CaptureFeatureForProductIdAction::main($data);
69
                break;
70
            case 'sendPBXMetrics':
71
                $res = SendMetricsAction::main();
72
                break;
73
            case 'ping':
74
                $res = PingAction::main();
75
                break;
76
            default:
77
                $res->messages['error'][] = "Unknown action - $action in " . __CLASS__;
78
        }
79
80
        $res->function = $action;
81
82
        return $res;
83
    }
84
}