Passed
Push — master ( bda737...e0ed8e )
by Nils
09:32
created

ItemController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B listAction() 0 35 6
1
<?php
2
/**
3
 * Teampass - a collaborative passwords manager.
4
 * ---
5
 * This library is distributed in the hope that it will be useful,
6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8
 * ---
9
 *
10
 * @project   Teampass API
11
 *
12
 * @file      ItemControler.php
13
 * ---
14
 *
15
 * @author    Nils Laumaillé ([email protected])
16
 *
17
 * @copyright 2009-2022 Teampass.net
18
 *
19
 * @license   https://spdx.org/licenses/GPL-3.0-only.html#licenseText GPL-3.0
20
 * ---
21
 *
22
 * @see       https://www.teampass.net
23
 */
24
class ItemController extends BaseController
25
{
26
    /**
27
     * "/user/list" Endpoint - Get list of users
28
     */
29
    public function listAction()
30
    {
31
        $strErrorDesc = '';
32
        $requestMethod = $_SERVER["REQUEST_METHOD"];
33
        $arrQueryStringParams = $this->getQueryStringParams();
34
35
        if (strtoupper($requestMethod) == 'GET') {
36
            try {
37
                $itemModel = new ItemModel();
38
 
39
                $intLimit = 10;
40
                if (isset($arrQueryStringParams['limit']) && $arrQueryStringParams['limit']) {
41
                    $intLimit = $arrQueryStringParams['limit'];
42
                }
43
 
44
                $arrUsers = $itemModel->getUsers($intLimit);
0 ignored issues
show
Bug introduced by
The method getUsers() does not exist on ItemModel. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

44
                /** @scrutinizer ignore-call */ 
45
                $arrUsers = $itemModel->getUsers($intLimit);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
                $responseData = json_encode($arrUsers);
46
            } catch (Error $e) {
47
                $strErrorDesc = $e->getMessage().'Something went wrong! Please contact support.';
48
                $strErrorHeader = 'HTTP/1.1 500 Internal Server Error';
49
            }
50
        } else {
51
            $strErrorDesc = 'Method not supported';
52
            $strErrorHeader = 'HTTP/1.1 422 Unprocessable Entity';
53
        }
54
 
55
        // send output
56
        if (!$strErrorDesc) {
57
            $this->sendOutput(
58
                $responseData,
59
                array('Content-Type: application/json', 'HTTP/1.1 200 OK')
60
            );
61
        } else {
62
            $this->sendOutput(json_encode(array('error' => $strErrorDesc)), 
63
                array('Content-Type: application/json', $strErrorHeader)
64
            );
65
        }
66
    }
67
}