Completed
Push — FVSv2 ( 1ec6b9...63e0fa )
by Patrick
01:36
created

VolunteerAPI::isVolunteerAdmin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
class VolunteerAPI extends Http\Rest\DataTableAPI
4
{
5
    protected $isAdmin = null;
6
    protected $isLead = null;
7
8
    public function __construct($dataTableName, $idField = '_id')
9
    {
10
        parent::__construct('fvs', $dataTableName, $idField);
1 ignored issue
show
Documentation introduced by
$idField 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...
11
    }
12
13
    protected function isVolunteerAdmin($request)
14
    {
15
        $this->validateLoggedIn($request);
16
        if($this->isAdmin === null)
17
        {
18
            $this->isAdmin = $this->user->isInGroupNamed('VolunteerAdmins');
1 ignored issue
show
Bug introduced by
The property user does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
        }
20
        return $this->isAdmin;
21
    }
22
23
    protected function canCreate($request)
24
    {
25
        return $this->isVolunteerAdmin($request);
26
    }
27
}
28