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
Branch master (57668c)
by Nikhil
13:19 queued 05:38
created

GuitarController::store()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 32
ccs 0
cts 28
cp 0
rs 8.439
cc 5
eloc 22
nc 3
nop 2
crap 30
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Events\GuitarWasCreated;
6
use App\Events\WarehouseWasUpdated;
7
use App\Guitar;
8
use App\Purchase;
9
use App\Rack;
10
use Illuminate\Http\Request;
11
12
class GuitarController extends Controller
13
{
14
    /**
15
     * Save the guitar.
16
     *
17
     * @param $id
18
     */
19
    public function store($id, Request $request)
20
    {
21
        $purchase = Purchase::findOrFail($id);
22
        if ( ! $purchase->hasArrived() || ! $purchase->isPendingStorage()) {
23
            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...
24
                422);
25
        }
26
27
        $this->validate($request, [
28
            'rack_id'   => 'required|exists:racks,id,make_id,' . $purchase->make_id,
29
            'model_id'  => 'required|exists:models,id,make_id,' . $purchase->make_id,
30
            'colour'    => 'required|string|max:255',
31
            'damaged'   => 'boolean',
32
            'condition' => 'required_if:damaged,true',
33
            'price'     => 'required|numeric|min:1',
34
        ]);
35
36
        $rack = Rack::find($request->input('rack_id'));
37
        if ($rack->used >= $rack->capacity) {
38
            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...
39
        }
40
41
        $guitar = Guitar::create($request->only(['rack_id', 'model_id', 'colour', 'price']) + [
42
                'make_id'     => $purchase->make_id,
43
                'purchase_id' => $purchase->id,
44
                'damaged'     => $request->input('damaged'),
45
                'condition'   => $request->input('damaged') ? $request->input('condition') : null
46
            ]);
47
48
        event(new GuitarWasCreated($guitar));
49
        event(new WarehouseWasUpdated($rack->warehouse));
0 ignored issues
show
Unused Code introduced by
The call to WarehouseWasUpdated::__construct() has too many arguments starting with $rack->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...
50
    }
51
}
52