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   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 9
lcom 2
cbo 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A index() 0 22 2
B store() 0 37 6
1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\Api\TransactionRequest;
7
use App\Models\TransactionStatus;
8
use App\Models\TransactionType;
9
use App\Services\TransactionService;
10
use App\Transformers\TransactionTransfomer;
11
use Auth;
12
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
13
14
class TransactionController extends Controller
15
{
16
    /**
17
     * @var TransactionService
18
     */
19
    private $transactionService;
20
21
    /**
22
     * TransactionController constructor.
23
     *
24
     * @param TransactionService $transactionService
25
     */
26
    public function __construct(TransactionService $transactionService)
27
    {
28
        $this->transactionService = $transactionService;
29
    }
30
31
    public function index()
32
    {
33
        $column = 'created_at';
34
        $direction = 'desc';
35
36
        // add support for sorting in vuetable-2
37
        $sort = request()->get('sort');
38
        if ($sort) {
39
            list($column, $direction) = explode('|', $sort);
40
        }
41
42
        $paginator = Auth::user()->transactions()
43
            ->orderBy($column, $direction)
44
            ->paginate(10);
45
46
        $transactions = $paginator->getCollection();
47
48
        return fractal()
49
            ->collection($transactions)
50
            ->transformWith(new TransactionTransfomer())
51
            ->paginateWith(new IlluminatePaginatorAdapter($paginator));
52
    }
53
54
    public function store(TransactionRequest $request)
55
    {
56
        $data = collect($request->all());
57
        $user = Auth::user();
58
        $isJsonRequest = $request->isJson();
59
60
        // ensure payee exists
61
        $payeeName = $request->input('payee');
62
        $payee = Auth::user()->payees()->whereName($payeeName)->first();
63
        if (!empty($payeeName) && !$payee) {
64
            $payee = Auth::user()->payees()->create(['name' => $payeeName]);
65
        }
66
67
        $type = TransactionType::whereName($data->get('transaction_type'))->firstOrFail();
68
        $account = $user->accounts()->whereName($data->get('account'))->firstOrFail();
69
        $category = $user->categories()->rootCategories()->whereName(($data->get('category')))->firstOrFail();
70
71
        $toaccount = $user->accounts()->whereName($data->get('to_account'))->first();
72
        $status = TransactionStatus::whereName($data->get('transaction_status'))->first();
73
        $subcategory = $user->categories()->subCategories()->whereName($data->get('sub_category'))->first();
74
75
        $resolvedData = collect([
76
            'transaction_type'   => $type->id,
77
            'transaction_status' => $status ? $status->id : null,
78
            'account'            => $account->id,
79
            'to_account'         => $toaccount ? $toaccount->id : null,
80
            'payee'              => $payee->id,
81
            'category'           => $category->id,
82
            'subcategory'        => $subcategory ? $subcategory->id : null,
83
        ]);
84
85
        $data = $data->merge($resolvedData);
86
87
        $this->transactionService->createTransaction(Auth::user(), $data, null, $isJsonRequest);
88
89
        return response('', 201);
90
    }
91
}
92