Passed
Push — develop ( faa3f8...82f9ab )
by Francisco
03:19
created

ExchangeController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 50.98 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 26
loc 51
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A decline() 13 13 1
A __construct() 0 3 1
A confirm() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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('can.exchange');
19
    }
20
21
    /**
22
     * Store a confirmation of an exchange in storage.
23
     *
24
     * @param int $id
25
     *
26
     * @return \Illuminate\Http\Response
27
     */
28 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...
29
    {
30
        $exchange = DB::transaction(function () use ($id) {
31
            $exchange = student()->proposedExchanges()->findOrFail($id);
32
33
            return $exchange->perform();
34
        });
35
36
        event(new ExchangeWasConfirmed($exchange));
37
        flash('The shift exchange request was successfully confirmed.')->success();
38
39
        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...
40
    }
41
42
    /**
43
     * Store a decline of an exchange in storage.
44
     *
45
     * @param int $id
46
     *
47
     * @return \Illuminate\Http\Response
48
     */
49 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...
50
    {
51
        $exchange = DB::transaction(function () use ($id) {
52
            $exchange = student()->proposedExchanges()->findOrFail($id);
53
            $exchange->delete();
54
55
            return $exchange;
56
        });
57
58
        event(new ExchangeWasDeclined($exchange));
59
        flash('The shift exchange request was successfully declined.')->success();
60
61
        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...
62
    }
63
}
64