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.

WarehouseController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 10
Bugs 1 Features 6
Metric Value
wmc 6
c 10
b 1
f 6
lcom 1
cbo 6
dl 0
loc 86
ccs 30
cts 30
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 4 1
A destroy() 0 6 1
A getIdsFrom() 0 4 1
A store() 0 14 1
A update() 0 18 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
            'racks.*.name'     => 'required|string|max:255',
41
            'racks.*.make_id'  => 'required|exists:makes,id',
42
            'racks.*.capacity' => 'required|integer|min:1',
43
        ]);
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));
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
            'racks.*.id'       => 'exists:racks,id',
62
            'racks.*.name'     => 'required|string|max:255',
63
            'racks.*.make_id'  => 'required|exists:makes,id',
64
            'racks.*.capacity' => 'required|integer|min:1',
65
        ]);
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));
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
        event(new WarehouseWasDeleted($warehouse));
85 2
        $warehouse->delete();
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