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 ( d22bab...41c46a )
by Nikhil
15:46 queued 08:03
created

PurchaseController::getSupplier()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.7898

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 13
ccs 5
cts 9
cp 0.5556
rs 9.4285
cc 3
eloc 7
nc 4
nop 1
crap 3.7898
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 1
        );
43 1
        event(new PurchaseWasCreated($purchase));
44 1
    }
45
46
    /**
47
     * Remove the specified resource from storage.
48
     *
49
     * @param  int $id
50
     */
51 1
    public function destroy($id)
52
    {
53 1
        $purchase = Purchase::findOrFail($id);
54 1
        $purchase->delete();
55 1
        event(new PurchaseWasDeleted($purchase));
0 ignored issues
show
Unused Code introduced by
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...
56 1
    }
57
58
    /**
59
     * Rules for validation depending whether or not supplier has been provided.
60
     *
61
     * @param $supplierId
62
     *
63
     * @return array
64
     */
65 5
    private function rules($supplierId)
66
    {
67
        $rules = [
68 5
            'id'                => 'integer|min:1|unique:suppliers,id',
69 5
            'make_id'           => 'required|exists:makes,id',
70 5
            'quantity'          => 'required|integer|min:1',
71 5
            'price'             => 'required|numeric|min:1',
72 5
            'date_purchased'    => 'required|date_format:Y-m-d|before:tomorrow',
73 5
            'delivery_date'     => 'required|date_format:Y-m-d|after:date_purchased',
74 5
            'supplier.name'     => 'required_if:supplier_id,new|string|max:255',
75
            'supplier.location' => 'required_if:supplier_id,new|string|max:255'
76 5
        ];
77 5
        if ($supplierId != 'new') {
78 4
            $rules += ['supplier_id' => 'required|integer|exists:suppliers,id'];
79 4
        }
80
81 5
        return $rules;
82
    }
83
84
    /**
85
     * Get the supplier depending on the request.
86
     *
87
     * @param $request
88
     *
89
     * @return Supplier
90
     */
91 1
    private function getSupplier($request)
92
    {
93 1
        $supplier = Supplier::find($request->input('supplier_id')) ?: Supplier::create([
94
            'name'     => $request->input('supplier.name'),
95
            'location' => $request->input('supplier.location'),
96 1
        ]);
97
98 1
        if ($supplier->wasRecentlyCreated) {
99
            event(new SupplierWasCreated($supplier));
0 ignored issues
show
Unused Code introduced by
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...
100
        }
101
102 1
        return $supplier;
103
    }
104
}
105