Completed
Push — master ( 470265...410c93 )
by Patrick
01:39
created

ShiftSchedule   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 87
Duplicated Lines 40.23 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 35
loc 87
rs 10
c 0
b 0
f 0
wmc 20
lcom 0
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRoleNameFromID() 0 23 4
A shiftSort() 0 4 1
B shiftTimeSort() 21 21 7
A getStringBetween() 0 11 2
A daySort() 0 6 1
A groupSort() 14 14 5

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
namespace Schedules;
3
4
trait ShiftSchedule
5
{
6
    public function getRoleNameFromID($roleID)
7
    {
8
        static $roles = null;
9
        if($roles === null)
10
        {
11
            $dataTable = \DataSetFactory::getDataTableByNames('fvs', 'roles');
12
            $tmp = $dataTable->read();
13
            $roles = array();
14
            $count = count($tmp);
15
            for($i = 0; $i < $count; $i++)
16
            {
17
                if(isset($tmp[$i]['display_name']))
18
                {
19
                    $roles[$tmp[$i]['short_name']] = $tmp[$i]['display_name'];
20
                }
21
                else
22
                {
23
                    $roles[$tmp[$i]['short_name']] = $tmp[$i]['short_name'];
24
                }
25
            }
26
        }
27
        return $roles[$roleID];
28
    }
29
30
    public function shiftSort($a, $b)
31
    {
32
        return strcmp($this->getRoleNameFromID($a['roleID']), $this->getRoleNameFromID($b['roleID']));
33
    }
34
35 View Code Duplication
    public function shiftTimeSort($a, $b)
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...
36
    {
37
        $interval = $a['startTime']->diff($b['startTime']);
38
        if($interval->invert === 0)
39
        {
40
            if($interval->h || $interval->i)
41
            {
42
                return -1;
43
            }
44
            else
45
            {
46
                return 0;
47
            }
48
        }
49
        else if($interval->invert === 1 && ($interval->h || $interval->days))
50
        {
51
            return 1;
52
        }
53
        print_r($interval);
54
        die();
55
    }
56
57
    public function getStringBetween($string, $start, $end)
58
    {
59
        $index = strpos($string, $start);
60
        if($index === false)
61
        {
62
            return $string;
63
        }
64
        $index++;
65
        $len = strpos($string, $end, $index) - $index;
66
        return substr($string, $index, $len);
67
    }
68
69
    public function daySort($a, $b)
70
    {
71
        $a_date = $this->getStringBetween($a, '(', ')');
72
        $b_date = $this->getStringBetween($b, '(', ')'); 
73
        return strcasecmp($a_date, $b_date);
74
    }
75
76 View Code Duplication
    public function groupSort($a, $b)
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...
77
    {
78
        $aArr = explode(' ', $a);
79
        $bArr = explode(' ', $b);
80
        if($aArr[1] === 'PM' && $bArr[1] === 'AM')
81
        {
82
            return 1;
83
        }
84
        else if($aArr[1] === 'AM' && $bArr[1] === 'PM')
85
        {
86
            return -1;
87
        }
88
        return strcmp($a, $b);
89
    }
90
}
91