Passed
Push — develop ( a18085...de8258 )
by Francisco
14:47
created

ExchangeController::decline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Judite\Models\Exchange;
7
use Illuminate\Support\Facades\DB;
8
use App\Events\ExchangeWasDeclined;
9
use App\Events\ExchangeWasConfirmed;
10
11
class ExchangeController extends Controller
12
{
13
    /**
14
     * Create a new controller instance.
15
     */
16
    public function __construct()
17
    {
18
        $this->middleware('auth');
19
        $this->middleware('can.student');
20
        $this->middleware('student.verified');
21
        $this->middleware('can.exchange');
22
    }
23
24
    /**
25
     * Store a confirmation of an exchange in storage.
26
     *
27
     * @param int $id
28
     *
29
     * @return \Illuminate\Http\Response
30
     */
31 View Code Duplication
    public function confirm($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
32
    {
33
        $exchange = DB::transaction(function () use ($id) {
34
            $exchange = student()->proposedExchanges()->findOrFail($id);
35
36
            return $exchange->perform();
37
        });
38
39
        event(new ExchangeWasConfirmed($exchange));
40
        flash('The shift exchange request was successfully confirmed.')->success();
41
42
        return redirect()->back();
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
43
    }
44
45
    /**
46
     * Store a decline of an exchange in storage.
47
     *
48
     * @param int $id
49
     *
50
     * @return \Illuminate\Http\Response
51
     */
52 View Code Duplication
    public function decline($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
53
    {
54
        $exchange = DB::transaction(function () use ($id) {
55
            $exchange = student()->proposedExchanges()->findOrFail($id);
56
            $exchange->delete();
57
58
            return $exchange;
59
        });
60
61
        event(new ExchangeWasDeclined($exchange));
62
        flash('The shift exchange request was successfully declined.')->success();
63
64
        return redirect()->back();
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
65
    }
66
67
    /**
68
     * Remove the specified resource from storage.
69
     *
70
     * @param int $id
71
     *
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function destroy($id)
75
    {
76
        DB::transaction(function () use ($id) {
77
            student()->requestedExchanges()->findOrFail($id)->delete();
78
        });
79
80
        flash('The shift exchange request was successfully deleted.')->success();
81
82
        return redirect()->back();
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
83
    }
84
}
85