RatingsApiController::index()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * The ratings API controller provides access to bulk ratings information for a list of addons provided
5
 * via the `addons` query string argument, comma delimited.
6
 *
7
 * For individual (including detailed) rating metrics, use the RatingApiController
8
 */
9
class RatingsApiController extends ApiController
10
{
11
    private static $allowed_actions = [
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
12
        'index',
13
    ];
14
15
    public function index(SS_HTTPRequest $request)
16
    {
17
        if (!$request->getVar('addons')) {
18
            return $this->formatResponse([
19
                'success' => false,
20
                'message' => 'Missing or incomplete module names',
21
            ]);
22
        }
23
24
        $addonNames = $request->getVar('addons');
0 ignored issues
show
Unused Code introduced by
$addonNames 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...
25
        /** @var Addon[] $addons */
26
        $addons = Addon::get()
27
            ->filter(['Name' => explode(',', $request->getVar('addons'))])
28
            ->map('Name', 'Rating');
29
30
        return $this->formatResponse([
31
            'success' => true,
32
            'ratings' => $addons->toArray()
0 ignored issues
show
Bug introduced by
The method toArray cannot be called on $addons (of type 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.

Loading history...
33
        ]);
34
    }
35
}
36