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

VolunteerDepartment   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 40.54 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 15
loc 37
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 3
A getLeadEmails() 0 16 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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