Completed
Pull Request — develop (#51)
by Patrick
02:57
created

AreasAPI::validateIsAdmin()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A AreasAPI::canUpdate() 0 5 1
1
<?php
2
class AreasAPI extends ProfilesAdminDataAPI
3
{
4
    public function __construct()
5
    {
6
        parent::__construct('profiles', 'area', 'short_name');
0 ignored issues
show
Documentation introduced by
'short_name' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
7
    }
8
9
    public function setup($app)
10
    {
11
        parent::setup($app);
12
        $app->get('/{name}/leads', array($this, 'getLeads'));
13
    }
14
15
    protected function canCreate($request)
16
    {
17
        $this->validateIsAdmin($request);
18
        return true;
19
    }
20
21
    protected function canUpdate($request, $entity)
22
    {
23
        $this->validateIsAdmin($request);
24
        return true;
25
    }
26
27
    public function getLeads($request, $response, $args)
28
    {
29
        $this->validateLoggedIn($request);
30
        $dataTable = DataSetFactory::getDataTableByNames('profiles', 'position');
31
        $odata = $request->getAttribute('odata', new \ODataParams(array()));
32
        $leads = $dataTable->read(new \Data\Filter("area eq '".$args['name']."'"), $odata->select, $odata->top,
33
                                  $odata->skip, $odata->orderby);
34
        if(empty($leads))
35
        {
36
            return $response->withStatus(404);
37
        }
38
        return $response->withJson($leads);
39
    }
40
}
41
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
42