Completed
Push — FVSv2 ( 9a40f1...ab906d )
by Patrick
01:31
created

VolunteerDepartment   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 87.27 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 48
loc 55
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 15 15 3
A getLeadEmails() 16 16 3
A getPrivateDepartments() 17 17 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 View Code Duplication
    public function getLeadEmails()
1 ignored issue
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...
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 View Code Duplication
    public static function getPrivateDepartments()
1 ignored issue
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...
40
    {
41
        $dataTable = DataSetFactory::getDataTableByNames('fvs', 'departments');
42
        $filter = new \Data\Filter('public eq false');
43
        $depts = $dataTable->read($filter);
44
        $res = array();
45
        if(empty($depts))
46
        {
47
            return $res;
48
        }
49
        $count = count($depts);
50
        for($i = 0; $i < $count; $i++)
51
        {
52
            array_push($res, $depts[$i]['departmentID']);
53
        }
54
        return $res;
55
    }
56
}
57