Passed
Push — develop ( a56058...ddfce4 )
by Nikolay
04:39
created

EnableModuleAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 12
c 0
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A main() 0 15 2
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\Modules;
21
22
use MikoPBX\Common\Providers\PBXConfModulesProvider;
23
use MikoPBX\Modules\PbxExtensionState;
24
use MikoPBX\PBXCoreREST\Lib\PBXApiResult;
25
26
/**
27
 *  Class EnableModule
28
 *  Enables extension module.
29
 *
30
 * @package MikoPBX\PBXCoreREST\Lib\Modules
31
 */
32
class EnableModuleAction extends \Phalcon\Di\Injectable
33
{
34
    /**
35
     * Enables extension module.
36
     *
37
     * @param string $moduleUniqueID
38
     *
39
     * @return PBXApiResult An object containing the result of the API call.
40
     */
41
    public static function main(string $moduleUniqueID): PBXApiResult
42
    {
43
        $res = new PBXApiResult();
44
        $res->processor = __METHOD__;
45
        $moduleStateProcessor = new PbxExtensionState($moduleUniqueID);
46
        if ($moduleStateProcessor->enableModule() === false) {
47
            $res->success = false;
48
            $res->messages = $moduleStateProcessor->getMessages();
49
        } else {
50
            PBXConfModulesProvider::recreateModulesProvider();
51
            $res->data = $moduleStateProcessor->getMessages();
52
            $res->success = true;
53
        }
54
55
        return $res;
56
    }
57
}