Issues (42)

app/Schedules/class.ShiftSchedule.php (2 issues)

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);
0 ignored issues
show
It seems like $tmp can also be of type boolean; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

14
            $count = count(/** @scrutinizer ignore-type */ $tmp);
Loading history...
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
    public function shiftTimeSort($a, $b)
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();
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
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
    public function groupSort($a, $b)
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