Completed
Push — FVSv2 ( 65de7f...ae4b85 )
by Patrick
01:34
created

VolunteerDepartment::getLeadEmails()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 0
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
class VolunteerDepartment
3
{
4
    protected $dbData;
5
6 View Code Duplication
    public function __construct($departmentID, $dbData = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
    {
8
        if($dbData === null)
9
        {
10
            $dataTable = DataSetFactory::getDataTableByNames('fvs', 'departments');
11
            $filter = new \Data\Filter('departmentID eq '.$departmentID);
12
            $depts = $dataTable->read($filter);
13
            if(empty($depts))
14
            {
15
                throw new Exception('Unable to locate department with ID '.$departmentID);
16
            }
17
            $dbData = $depts[0];
18
        }
19
        $this->dbData = $dbData;
20
    }
21
22
    public function getLeadEmails()
23
    {
24
        $leadTitle = $dbData['lead'];
0 ignored issues
show
Bug introduced by
The variable $dbData does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
25
        $auth = \AuthProvider::getInstance();
26
        $users = $auth->getUsersByFilter(new \Data\Filter('title eq '.$leadTitle), array('mail'));
27
        if(empty($users))
28
        {
29
            return null;
30
        }
31
        $count = count($users);
32
        for($i = 0; $i < $count; $i++)
33
        {
34
            $users[$i] = $users[$i]['mail'];
35
        }
36
        return $users;
37
    }
38
}
39