GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( d22bab...41c46a )
by Nikhil
15:46 queued 08:03
created

WarehouseController::getIdsFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Events\WarehouseWasCreated;
6
use App\Events\WarehouseWasDeleted;
7
use App\Events\WarehouseWasUpdated;
8
use App\Warehouse;
9
use Illuminate\Http\Request;
10
use Illuminate\Http\Response;
11
12
class WarehouseController extends Controller
13
{
14
    /**
15
     * New instance of warehouse controller.
16
     */
17 14
    public function __construct()
18
    {
19 14
        $this->middleware('auth');
20 14
    }
21
22
    /**
23
     * List the warehouses.
24
     * @return Response
25
     */
26 1
    public function index()
27
    {
28 1
        return view('warehouses.index');
29
    }
30
31
    /**
32
     * Create a new warehouse.
33
     *
34
     * @param Request $request
35
     */
36 6
    public function store(Request $request)
37
    {
38 6
        $this->validate($request, [
39 6
            'name'             => 'required|string|max:255',
40 6
            'racks.*.name'     => 'required|string|max:255',
41 6
            'racks.*.make_id'  => 'required|exists:makes,id',
42 6
            'racks.*.capacity' => 'required|integer|min:1',
43 6
        ]);
44
45 2
        $warehouse = Warehouse::create($request->only(['name']));
46 2
        $racks     = $request->input('racks', []);
47 2
        $warehouse->addRacks($racks);
0 ignored issues
show
Bug introduced by
It seems like $racks defined by $request->input('racks', array()) on line 46 can also be of type string; however, App\Warehouse::addRacks() does only seem to accept object<Illuminate\Databa...quent\Collection>|array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
48 2
        event(new WarehouseWasCreated($warehouse));
0 ignored issues
show
Unused Code introduced by
The call to WarehouseWasCreated::__construct() has too many arguments starting with $warehouse.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
49 2
    }
50
51
    /**
52
     * Update the warehouse.
53
     *
54
     * @param $id
55
     * @param Request $request
56
     */
57 1
    public function update(Request $request, $id)
58
    {
59 1
        $this->validate($request, [
60 1
            'name'             => 'required|string|max:255',
61 1
            'racks.*.id'       => 'exists:racks,id',
62 1
            'racks.*.name'     => 'required|string|max:255',
63 1
            'racks.*.make_id'  => 'required|exists:makes,id',
64 1
            'racks.*.capacity' => 'required|integer|min:1',
65 1
        ]);
66
67 1
        $warehouse = Warehouse::findOrFail($id);
68 1
        $warehouse->update($request->only(['name']));
69
70 1
        $racks = $request->input('racks', []);
71 1
        $warehouse->removeRacksNotIn($this->getIdsFrom($racks));
72 1
        $warehouse->addOrUpdateRacks($racks);
73 1
        event(new WarehouseWasUpdated($warehouse));
0 ignored issues
show
Unused Code introduced by
The call to WarehouseWasUpdated::__construct() has too many arguments starting with $warehouse.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
74 1
    }
75
76
    /**
77
     * Delete the warehouse.
78
     *
79
     * @param $id
80
     */
81 2
    public function destroy($id)
82
    {
83 2
        $warehouse = Warehouse::findOrFail($id);
84 2
        $warehouse->delete();
85 2
        event(new WarehouseWasDeleted($warehouse));
0 ignored issues
show
Unused Code introduced by
The call to WarehouseWasDeleted::__construct() has too many arguments starting with $warehouse.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
86 2
    }
87
88
    /**
89
     * @param $racks
90
     *
91
     * @return array
92
     */
93 1
    private function getIdsFrom($racks)
94
    {
95 1
        return array_filter(array_pluck($racks, 'id'));
96
    }
97
}
98