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

AvailableAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
c 1
b 0
f 0
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A main() 0 18 3
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright © 2017-2024 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\Users;
21
22
23
use MikoPBX\Common\Models\Users;
24
use MikoPBX\PBXCoreREST\Lib\PBXApiResult;
25
26
/**
27
 * Processes Users management requests
28
 *
29
 * @package MikoPBX\PBXCoreREST\Lib\Iax
30
 */
31
class AvailableAction extends \Phalcon\Di\Injectable
32
{
33
    /**
34
     * Processes Users management requests
35
     *
36
     * @return PBXApiResult An object containing the result of the API call.
37
     */
38
    public static function main(array $data): PBXApiResult
39
    {
40
        $res = new PBXApiResult();
41
        $res->processor = __METHOD__;
42
        if (!empty($data['email'])) {
43
            $record = Users::findFirstByEmail($data['email']);
44
            if ($record) {
45
                $res->data['userId'] = $record->id;
46
                $res->data['represent'] = $record->getRepresent();
47
                $res->data['available'] = false;
48
            } else {
49
                $res->data['available'] = true;
50
            }
51
            $res->success = true;
52
        } else {
53
            $res->messages['error'][] = 'Empty email value in POST/GET data';
54
        }
55
        return $res;
56
    }
57
}