for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* The ratings API controller provides access to bulk ratings information for a list of addons provided
* via the `addons` query string argument, comma delimited.
*
* For individual (including detailed) rating metrics, use the RatingApiController
*/
class RatingsApiController extends ApiController
{
private static $allowed_actions = [
'index',
];
public function index(SS_HTTPRequest $request)
if (!$request->getVar('addons')) {
return $this->formatResponse([
'success' => false,
'message' => 'Missing or incomplete module names',
]);
}
$addonNames = $request->getVar('addons');
$addonNames
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
/** @var Addon[] $addons */
$addons = Addon::get()
->filter(['Name' => explode(',', $request->getVar('addons'))])
->map('Name', 'Rating');
'success' => true,
'ratings' => $addons->toArray()
toArray
$addons
array<integer,object<Addon>>
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.