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 ( f3afd8...f29bd1 )
by Nikhil
13:23
created

GuitarController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Events\GuitarWasCreated;
6
use App\Events\GuitarWasDeleted;
7
use App\Events\GuitarWasUpdated;
8
use App\Guitar;
9
use App\Purchase;
10
use App\Rack;
11
use Illuminate\Http\Request;
12
use Illuminate\Http\Response;
13
14
class GuitarController extends Controller
15
{
16
    /**
17
     * GuitarController constructor.
18
     */
19
    public function __construct()
20
    {
21
        $this->middleware('auth');
22
    }
23
24
    /**
25
     * List the guitars.
26
     * @return Response
27
     */
28
    public function index()
29
    {
30
        return view('guitars.index');
31
    }
32
33
    /**
34
     * Save the guitar.
35
     *
36
     * @param $id
37
     * @param Request $request
38
     *
39
     * @return Response
40
     */
41
    public function store($id, Request $request)
42
    {
43
        $purchase = Purchase::findOrFail($id);
44
        if ( ! $purchase->hasArrived() || ! $purchase->isPendingStorage()) {
45
            return response(['purchase' => ['The purchase has not yet arrived or doesn\'t require addition of guitars.']],
1 ignored issue
show
Documentation introduced by
array('purchase' => arra...addition of guitars.')) is of type array<string,array<integ...,{\"0\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
                422);
47
        }
48
49
        $this->validate($request, [
50
            'rack_id'   => 'required|exists:racks,id,make_id,' . $purchase->make_id,
51
            'model_id'  => 'required|exists:models,id,make_id,' . $purchase->make_id,
52
            'colour'    => 'required|string|max:255',
53
            'damaged'   => 'boolean',
54
            'condition' => 'required_if:damaged,true',
55
            'price'     => 'required|numeric|min:1',
56
        ]);
57
58
        $rack = Rack::find($request->input('rack_id'));
59 View Code Duplication
        if ($rack->used >= $rack->capacity) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
            return response(['rack_id' => ['The selected rack is full.']], 422);
1 ignored issue
show
Documentation introduced by
array('rack_id' => array...lected rack is full.')) is of type array<string,array<integ...,{\"0\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
        }
62
63
        $guitar = Guitar::create($request->only(['rack_id', 'model_id', 'colour', 'price']) + [
64
                'make_id'     => $purchase->make_id,
65
                'purchase_id' => $purchase->id,
66
                'damaged'     => $request->input('damaged'),
67
                'condition'   => $request->input('damaged') ? $request->input('condition') : null
68
            ]);
69
70
        event(new GuitarWasCreated($guitar));
71
    }
72
73
    /**
74
     * Update the guitar.
75
     *
76
     * @param $id
77
     * @param Request $request
78
     *
79
     * @return Response
80
     */
81
    public function update($id, Request $request)
82
    {
83
        $guitar = Guitar::findOrFail($id);
84
        $this->validate($request, [
85
            'rack_id'   => 'required|exists:racks,id,make_id,' . $guitar->make_id,
86
            'model_id'  => 'required|exists:models,id,make_id,' . $guitar->make_id,
87
            'colour'    => 'required|string|max:255',
88
            'damaged'   => 'boolean',
89
            'condition' => 'required_if:damaged,true',
90
            'price'     => 'required|numeric|min:1',
91
        ]);
92
93
        $rack = Rack::find($request->input('rack_id'));
94 View Code Duplication
        if ($rack->used >= $rack->capacity) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
            return response(['rack_id' => ['The selected rack is full.']], 422);
1 ignored issue
show
Documentation introduced by
array('rack_id' => array...lected rack is full.')) is of type array<string,array<integ...,{\"0\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
96
        }
97
98
        $guitar = $guitar->update($request->only(['rack_id', 'model_id', 'colour', 'price']) + [
99
                'damaged'   => $request->input('damaged'),
100
                'condition' => $request->input('damaged') ? $request->input('condition') : null
101
            ]);
102
        event(new GuitarWasUpdated($guitar));
103
    }
104
105
    /**
106
     * Delete the guitar.
107
     *
108
     * @param $id
109
     */
110
    public function destroy($id)
111
    {
112
        $guitar = Guitar::findOrFail($id);
113
        event(new GuitarWasDeleted($guitar));
114
        $guitar->delete();
115
    }
116
}
117