Passed
Push — develop ( d906b2...768883 )
by Nikolay
05:15 queued 16s
created

GetPeerStatus::main()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 15
rs 9.9
cc 2
nc 3
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\Sip;
21
22
use MikoPBX\Core\System\Util;
23
use MikoPBX\PBXCoreREST\Lib\PBXApiResult;
24
25
/**
26
 * Retrieves the status of a SIP peer.
27
 *
28
 * @package MikoPBX\PBXCoreREST\Lib\Sip
29
 */
30
class GetPeerStatus extends \Phalcon\Di\Injectable
31
{
32
33
    /**
34
     * Retrieves the status of a SIP peer.
35
     *
36
     * @param string $peer The peer to retrieve the status for.
37
     *
38
     * @return PBXApiResult An object containing the result of the API call.
39
     */
40
    public static function main(string $peer): PBXApiResult
41
    {
42
        $res = new PBXApiResult();
43
        $res->processor = __METHOD__;
44
        try {
45
            $am = Util::getAstManager('off');
46
            $peers = $am->getPjSipPeer($peer);
47
            $res->success = true;
48
            $res->data = $peers;
49
        } catch (\Throwable $e) {
50
            $res->success = false;
51
            $res->messages[] = $e->getMessage();
52
        }
53
54
        return $res;
55
    }
56
}