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 ( 984397...f88331 )
by Nikhil
09:07
created

GuitarController::showSaleFor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 0
cp 0
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
crap 6
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\Events\SaleWasCreated;
9
use App\Guitar;
10
use App\Purchase;
11
use App\Rack;
12
use App\Sale;
13
use App\Shop;
14
use Illuminate\Http\Request;
15
use Illuminate\Http\Response;
16
17
class GuitarController extends Controller
18
{
19
    /**
20
     * GuitarController constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->middleware('auth');
25
    }
26
27
    /**
28
     * List the guitars.
29
     * @return Response
30
     */
31
    public function index()
32
    {
33
        return view('guitars.index');
34
    }
35
36
    /**
37
     * Save the guitar.
38
     *
39
     * @param $id
40
     * @param Request $request
41
     *
42
     * @return Response
43
     */
44
    public function store($id, Request $request)
45
    {
46
        $purchase = Purchase::findOrFail($id);
47
        if ( ! $purchase->hasArrived() || ! $purchase->isPendingStorage()) {
48
            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...
49
                422);
50
        }
51
52
        $this->validate($request, [
53
            'rack_id'   => 'required|exists:racks,id,make_id,' . $purchase->make_id,
54
            'model_id'  => 'required|exists:models,id,make_id,' . $purchase->make_id,
55
            'colour'    => 'required|string|max:255',
56
            'damaged'   => 'boolean',
57
            'condition' => 'required_if:damaged,true',
58
            'price'     => 'required|numeric|min:1',
59
        ]);
60
61
        $rack = Rack::find($request->input('rack_id'));
62 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...
63
            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...
64
        }
65
66
        $guitar = Guitar::create($request->only(['rack_id', 'model_id', 'colour', 'price']) + [
67
                'make_id'     => $purchase->make_id,
68
                'purchase_id' => $purchase->id,
69
                'damaged'     => $request->input('damaged'),
70
                'condition'   => $request->input('damaged') ? $request->input('condition') : null
71
            ]);
72
73
        event(new GuitarWasCreated($guitar));
74
    }
75
76
    /**
77
     * Update the guitar.
78
     *
79
     * @param $id
80
     * @param Request $request
81
     *
82
     * @return Response
83
     */
84
    public function update($id, Request $request)
85
    {
86
        $guitar = Guitar::findOrFail($id);
87
        $this->validate($request, [
88
            'rack_id'   => 'required|exists:racks,id,make_id,' . $guitar->make_id,
89
            'model_id'  => 'required|exists:models,id,make_id,' . $guitar->make_id,
90
            'colour'    => 'required|string|max:255',
91
            'damaged'   => 'boolean',
92
            'condition' => 'required_if:damaged,true',
93
            'price'     => 'required|numeric|min:1',
94
        ]);
95
96
        $rack = Rack::find($request->input('rack_id'));
97 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...
98
            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...
99
        }
100
101
        $guitar->update($request->only(['rack_id', 'model_id', 'colour', 'price']) + [
102
                'damaged'   => $request->input('damaged'),
103
                'condition' => $request->input('damaged') ? $request->input('condition') : null
104
            ]);
105
        event(new GuitarWasUpdated($guitar));
106
    }
107
108
    /**
109
     * Sell the guitar.
110
     *
111
     * @param $id
112
     * @param Request $request
113
     *
114
     * @return Response
115
     */
116
    public function sale($id, Request $request)
117
    {
118
        $guitar = Guitar::findOrFail($id);
119
120
        if ($guitar->isSold()) {
121
            return response(['guitar_id' => ['This guitar has already been sold.']], 422);
1 ignored issue
show
Documentation introduced by
array('guitar_id' => arr...s already been sold.')) 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...
122
        }
123
124
        $this->validate($request, [
125
            'customer_type' => 'required|in:individual,shop',
126
            'name'          => 'required|string|max:255',
127
            'address'       => 'required|string|max:255',
128
        ]);
129
130
        $shop = null;
131
        if ($request->input('customer_type') == 'shop') {
132
            $shop = Shop::create($request->only(['name', 'address']))->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Shop>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
133
        }
134
135
        $sale = Sale::create($request->only(['name', 'address']) + ['guitar_id' => $id, 'shop_id' => $shop]);
136
137
        event(new SaleWasCreated($sale));
138
    }
139
140
    /**
141
     * Delete the guitar.
142
     *
143
     * @param $id
144
     */
145
    public function destroy($id)
146
    {
147
        $guitar = Guitar::findOrFail($id);
148
        event(new GuitarWasDeleted($guitar));
149
        $guitar->delete();
150
    }
151
}
152