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.

TransactionController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\TransactionRequest;
6
use App\Models\Transaction;
7
use App\Services\TransactionService;
8
use Auth;
9
use Illuminate\Http\Request;
10
11
class TransactionController extends Controller
12
{
13
    /**
14
     * @var TransactionService
15
     */
16
    private $transactionService;
17
18
    /**
19
     * TransactionController constructor.
20
     *
21
     * @param TransactionService $transactionService
22
     */
23
    public function __construct(TransactionService $transactionService)
24
    {
25
        $this->transactionService = $transactionService;
26
    }
27
28
    /**
29
     * Show the form for creating a new resource.
30
     *
31
     * @return \Illuminate\Http\Response
32
     */
33
    public function create()
34
    {
35
        return view('transactions.create');
36
    }
37
38
    /**
39
     * Store a newly created resource in storage.
40
     *
41
     * @param TransactionRequest|Request $request
42
     *
43
     * @return \Illuminate\Http\Response
44
     */
45 View Code Duplication
    public function store(TransactionRequest $request)
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...
46
    {
47
        $files = $request->file('attachments');
48
49
        $data = collect($request->all());
50
        $this->transactionService->createTransactionWithUsage(Auth::user(), $data, $files);
0 ignored issues
show
Bug introduced by
It seems like $files defined by $request->file('attachments') on line 47 can also be of type object<Illuminate\Http\UploadedFile>; however, App\Services\Transaction...eTransactionWithUsage() does only seem to accept null|array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
51
52
        return redirect()->route('home')->with('status', __('mmex.created'));
53
    }
54
55
    /**
56
     * Update the specified resource in storage.
57
     *
58
     * @param TransactionRequest|Request $request
59
     * @param int                        $id
60
     *
61
     * @return \Illuminate\Http\Response
62
     */
63 View Code Duplication
    public function update(TransactionRequest $request, $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...
64
    {
65
        $files = $request->file('attachments');
66
67
        $data = collect($request->all());
68
        $this->transactionService->updateTransactionWithUsage(Auth::user(), $id, $data, $files);
0 ignored issues
show
Bug introduced by
It seems like $files defined by $request->file('attachments') on line 65 can also be of type object<Illuminate\Http\UploadedFile>; however, App\Services\Transaction...eTransactionWithUsage() does only seem to accept null|array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
69
70
        return redirect()->route('home')->with('status', __('mmex.updated'));
71
    }
72
73
    /**
74
     * Remove the specified resource from storage.
75
     *
76
     * @param int $id
77
     *
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function destroy($id)
81
    {
82
        abort_unless(Auth::user()->transactions()->whereId($id)->exists(), 403);
83
84
        Transaction::destroy($id);
85
    }
86
}
87