for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
function shiftGroup()
{
global $app;
global
Instead of relying on global state, we recommend one of these alternatives:
function myFunction($a, $b) { // Do something }
class MyClass { private $a; private $b; public function __construct($a, $b) { $this->a = $a; $this->b = $b; } public function myFunction() { // Do something } }
$app->get('(/)', 'getCurrentShiftList');
}
function getCurrentShiftList()
if(!$app->user)
throw new Exception('Must be logged in', ACCESS_DENIED);
$dataTable = DataSetFactory::getDataTableByNames('fvs', 'shifts');
$ret = false;
$ret
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.
$myVar
$higher
if($app->user->isInGroupNamed('VolunteerAdmins'))
$ret = $dataTable->read($app->odata->filter, $app->odata->select, $app->odata->top, $app->odata->skip, $app->odata->orderby);
else
$myDept = false;
if($app->user->isInGroupNamed('Lead'))
$myDept = \Volunteer\Shifts::getShiftsForLead($app->user, $app->odata->select);
$depts = \Volunteer\Shifts::getPublicShifts($app->odata->select);
if($myDept)
$depts = array_merge($depts, $myDept);
$ret = $depts;
echo json_encode($ret);
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state