Completed
Push — master ( ed6913...63632c )
by Patrick
01:43
created

VolunteerEvent::hasVolOnEEList()   B

Complexity

Conditions 10
Paths 7

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
nc 7
nop 2
dl 0
loc 21
rs 7.6666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
class VolunteerEvent extends VolunteerObject
3
{
4
    public function __construct($departmentID, $dbData = null)
5
    {
6
        parent::__construct($departmentID, $dbData, 'events', '_id');
7
    }
8
9
    public function hasVolOnEEList($uid, $eeListIndex)
10
    {
11
        if($eeListIndex === 1 || $eeListIndex === 0)
12
        {
13
            //Check earlier EE lists too
14
            $val = $this->hasVolOnEEList($uid, $eeListIndex+1);
15
            if($val === true)
16
            {
17
                return true;
18
            }
19
        }
20
        if(isset($this->dbData['eeLists']) && isset($this->dbData['eeLists'][$eeListIndex]))
21
        {
22
            $eeList = $this->dbData['eeLists'][$eeListIndex];
23
            if(isset($eeList[$uid]) && $eeList[$uid]['AAR'] === true && $eeList[$uid]['AF'] === true && $eeList[$uid]['Lead'] === true)
24
            {
25
                return true;
26
            }
27
        }
28
        return false;
29
    }
30
31
    public function addToEEList($uid, $eeListIndex)
32
    {
33
        if(!isset($this->dbData['eeLists']))
34
        {
35
            $this->dbData['eeLists'] = array();
36
        }
37
        if(!isset($this->dbData['eeLists'][$eeListIndex]))
38
        {
39
            $this->dbData['eeLists'][$eeListIndex] = array();
40
        }
41
        $eeList = $this->dbData['eeLists'][$eeListIndex];
0 ignored issues
show
Unused Code introduced by
$eeList is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
        if(!isset($this->dbData['eeLists'][$eeListIndex][$uid]))
43
        {
44
            $this->dbData['eeLists'][$eeListIndex][$uid] = array('AAR'=>false, 'AF'=>false, 'Lead'=>false);
45
            $dt = $this->getDataTable();
46
            $filter = $this->getDataFilter();
47
            return $dt->update($filter, $this->dbData);
48
        }
49
        return true;
50
    }
51
}
52