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 ( 8c82e7...44f2dc )
by Nikhil
09:16
created

app/Http/Controllers/PurchaseController.php (2 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Events\PurchaseWasCreated;
6
use App\Events\PurchaseWasDeleted;
7
use App\Events\SupplierWasCreated;
8
use App\Purchase;
9
use App\Supplier;
10
use Illuminate\Http\Request;
11
12
class PurchaseController extends Controller
13
{
14
    /**
15
     * PurchaseController constructor.
16
     */
17 10
    public function __construct()
18
    {
19 10
        $this->middleware('auth');
20 10
    }
21
22
    /**
23
     * Display a listing of the resource.
24
     *
25
     * @return \Illuminate\Http\Response
26
     */
27 1
    public function index()
28
    {
29 1
        return view('purchases.index');
30
    }
31
32
    /**
33
     * Store a newly created resource in storage.
34
     *
35
     * @param  \Illuminate\Http\Request $request
36
     */
37 5
    public function store(Request $request)
38
    {
39 5
        $this->validate($request, $this->rules($request->input('supplier_id')));
40 1
        $purchase = $this->getSupplier($request)->makePurchase(
41 1
            $request->only(['id', 'make_id', 'quantity', 'price', 'date_purchased', 'delivery_date'])
42
        );
43 1
        event(new PurchaseWasCreated($purchase));
44 1
    }
45
46
    /**
47
     * Show the specified resource.
48
     *
49
     * @param $id
50
     *
51
     * @return mixed
52
     */
53
    public function show($id)
54
    {
55
        $purchase = Purchase::findOrFail($id);
56
57
        return view('purchases.show')->withPurchase($purchase);
58
    }
59
60
    /**
61
     * Remove the specified resource from storage.
62
     *
63
     * @param  int $id
64
     */
65 1
    public function destroy($id)
66
    {
67 1
        $purchase = Purchase::findOrFail($id);
68 1
        $purchase->delete();
69 1
        event(new PurchaseWasDeleted($purchase));
0 ignored issues
show
The call to PurchaseWasDeleted::__construct() has too many arguments starting with $purchase.

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...
70 1
    }
71
72
    /**
73
     * Rules for validation depending whether or not supplier has been provided.
74
     *
75
     * @param $supplierId
76
     *
77
     * @return array
78
     */
79 5
    private function rules($supplierId)
80
    {
81
        $rules = [
82 5
            'id'                => 'integer|min:1|unique:suppliers,id',
83
            'make_id'           => 'required|exists:makes,id',
84
            'quantity'          => 'required|integer|min:1',
85
            'price'             => 'required|numeric|min:1',
86
            'date_purchased'    => 'required|date_format:Y-m-d|before:tomorrow',
87
            'delivery_date'     => 'required|date_format:Y-m-d|after:date_purchased',
88
            'supplier.name'     => 'required_if:supplier_id,new|string|max:255',
89
            'supplier.location' => 'required_if:supplier_id,new|string|max:255'
90
        ];
91 5
        if ($supplierId != 'new') {
92 4
            $rules += ['supplier_id' => 'required|integer|exists:suppliers,id'];
93
        }
94
95 5
        return $rules;
96
    }
97
98
    /**
99
     * Get the supplier depending on the request.
100
     *
101
     * @param $request
102
     *
103
     * @return Supplier
104
     */
105 1
    private function getSupplier($request)
106
    {
107 1
        $supplier = Supplier::find($request->input('supplier_id')) ?: Supplier::create([
108
            'name'     => $request->input('supplier.name'),
109 1
            'location' => $request->input('supplier.location'),
110
        ]);
111
112 1
        if ($supplier->wasRecentlyCreated) {
113
            event(new SupplierWasCreated($supplier));
0 ignored issues
show
The call to SupplierWasCreated::__construct() has too many arguments starting with $supplier.

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...
114
        }
115
116 1
        return $supplier;
117
    }
118
}
119