Completed
Pull Request — master (#48)
by Patrick
02:22
created

shift_api.php ➔ getCurrentShiftList()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
nc 6
nop 0
dl 0
loc 29
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
function shiftGroup()
4
{
5
    global $app;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
6
    $app->get('(/)', 'getCurrentShiftList');
7
}
8
9
function getCurrentShiftList()
10
{
11
    global $app;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
12
    if(!$app->user)
13
    {
14
        throw new Exception('Must be logged in', ACCESS_DENIED);
15
    }
16
    $dataTable = DataSetFactory::getDataTableByNames('fvs', 'shifts');
17
    $ret = false;
0 ignored issues
show
Unused Code introduced by
$ret is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
18
    if($app->user->isInGroupNamed('VolunteerAdmins'))
19
    {
20
        $ret = $dataTable->read($app->odata->filter, $app->odata->select, $app->odata->top, $app->odata->skip, $app->odata->orderby);
21
    }
22
    else
23
    {
24
        $myDept = false;
25
        if($app->user->isInGroupNamed('Lead'))
26
        {
27
            $myDept = \Volunteer\Shifts::getShiftsForLead($app->user, $app->odata->select);
28
        }
29
        $depts = \Volunteer\Shifts::getPublicShifts($app->odata->select);
30
        if($myDept)
31
        {
32
            $depts = array_merge($depts, $myDept);
33
        }
34
        $ret = $depts;
35
    }
36
    echo json_encode($ret);
37
}
38
39