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 — rewrite-laravel ( 96dff9...f203d9 )
by Oliver
11:47
created

MmexController::handle()   C

Complexity

Conditions 14
Paths 66

Size

Total Lines 79
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 79
rs 5.1058
c 0
b 0
f 0
cc 14
eloc 41
nc 66
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use App\Constants;
6
use App\Http\Controllers\Controller;
7
use App\Services\MmexFunctions;
8
use App\Services\MmexService;
9
use Illuminate\Http\Request;
10
use Log;
11
12
class MmexController extends Controller
13
{
14
    /**
15
     * @var MmexService
16
     */
17
    private $mmexService;
18
19
    /**
20
     * MmexController constructor.
21
     *
22
     * @param MmexService $mmexService
23
     */
24
    public function __construct(MmexService $mmexService)
25
    {
26
        $this->mmexService = $mmexService;
27
    }
28
29
    public function handle(Request $request)
30
    {
31
        $debugData = ['url' => $request->fullUrl(), 'data' => $request->all(), 'method' => $request->method()];
32
33
        Log::debug('Service Request', $debugData);
34
35
        $data = $request->all();
36
37
        $postData = null;
38
39
        if (isset($data['MMEX_Post'])) {
40
            $postData = json_decode($data['MMEX_Post']);
41
        } elseif (isset($data['postData'])) {
42
            $postData = json_decode($data['postData']);
43
        }
44
45
        if ($postData) {
46
            Log::debug('MmexController, $postData', [$postData]);
47
        }
48
49
        $function = $this->getFunction($data);
50
51
        if ($function == MmexFunctions::CheckGuid) {
52
            return $this->returnSuccess();
53
        }
54
55
        if ($function == MmexFunctions::CheckApiVersion) {
56
            return $this->returnText(Constants::$api_version);
57
        }
58
59
        if ($function == MmexFunctions::DownloadTransactions) {
60
            return $this->returnText($this->mmexService->getTransactions());
61
        }
62
63
        if ($function == MmexFunctions::DeleteBankAccounts) {
64
            $this->mmexService->deleteAccounts();
65
66
            return $this->returnSuccess();
67
        }
68
69
        if ($function == MmexFunctions::ImportBankAccounts) {
70
            $this->mmexService->importBankAccounts($postData);
71
72
            return $this->returnSuccess();
73
        }
74
75
        if ($function == MmexFunctions::DeletePayees) {
76
            $this->mmexService->deletePayees();
77
78
            return $this->returnSuccess();
79
        }
80
81
        if ($function == MmexFunctions::ImportPayees) {
82
            $this->mmexService->importPayees($postData);
83
84
            return $this->returnSuccess();
85
        }
86
87
        if ($function == MmexFunctions::DeleteCategories) {
88
            $this->mmexService->deleteCategories();
89
90
            return $this->returnSuccess();
91
        }
92
93
        if ($function == MmexFunctions::ImportCategories) {
94
            $this->mmexService->importCategories($postData);
95
96
            return $this->returnSuccess();
97
        }
98
99
        if ($function == MmexFunctions::DeleteTransactions) {
100
            $transactionId = $data["delete_group"];
101
            $this->mmexService->deleteTransactions($transactionId);
102
103
            return $this->returnSuccess();
104
        }
105
106
        return $data;
107
    }
108
109
    private function getFunction($data)
110
    {
111
        if (isset($data[MmexFunctions::CheckApiVersion])) {
112
            return MmexFunctions::CheckApiVersion;
113
        }
114
        if (isset($data[MmexFunctions::CheckGuid])) {
115
            return MmexFunctions::CheckGuid;
116
        }
117
        if (isset($data[MmexFunctions::DeleteAttachment])) {
118
            return MmexFunctions::DeleteAttachment;
119
        }
120
        if (isset($data[MmexFunctions::DeleteBankAccounts])) {
121
            return MmexFunctions::DeleteBankAccounts;
122
        }
123
        if (isset($data[MmexFunctions::DeleteCategories])) {
124
            return MmexFunctions::DeleteCategories;
125
        }
126
        if (isset($data[MmexFunctions::DeletePayees])) {
127
            return MmexFunctions::DeletePayees;
128
        }
129
        if (isset($data[MmexFunctions::DeleteTransactions])) {
130
            return MmexFunctions::DeleteTransactions;
131
        }
132
        if (isset($data[MmexFunctions::DonwloadAttachment])) {
133
            return MmexFunctions::DonwloadAttachment;
134
        }
135
        if (isset($data[MmexFunctions::DownloadTransactions])) {
136
            return MmexFunctions::DownloadTransactions;
137
        }
138
        if (isset($data[MmexFunctions::ImportBankAccounts])) {
139
            return MmexFunctions::ImportBankAccounts;
140
        }
141
        if (isset($data[MmexFunctions::ImportBankAccounts])) {
142
            return MmexFunctions::ImportBankAccounts;
143
        }
144
        if (isset($data[MmexFunctions::ImportPayees])) {
145
            return MmexFunctions::ImportPayees;
146
        }
147
        if (isset($data[MmexFunctions::DeleteCategories])) {
148
            return MmexFunctions::DeleteCategories;
149
        }
150
        if (isset($data[MmexFunctions::ImportCategories])) {
151
            return MmexFunctions::ImportCategories;
152
        }
153
154
        throw new \Exception('No valid function request!');
155
    }
156
157
    private function returnSuccess()
158
    {
159
        return $this->returnText(Constants::$operation_succeded);
160
    }
161
162
    private function returnText($text)
163
    {
164
        return response($text, 200)
0 ignored issues
show
Bug introduced by
The method header() does not exist on Symfony\Component\HttpFoundation\Response. Did you maybe mean sendHeaders()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
165
            ->header('Content-Type', 'text/plain; charset=UTF-8');
166
    }
167
}
168