Conditions | 16 |
Paths | 78 |
Total Lines | 118 |
Code Lines | 63 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
35 | public function handle(Request $request) |
||
36 | { |
||
37 | $user = Auth::guard('api')->user(); |
||
38 | abort_unless($user, 404, 'User not found!'); |
||
39 | |||
40 | $debugData = ['url' => $request->fullUrl(), 'data' => $request->all(), 'method' => $request->method()]; |
||
41 | |||
42 | Log::debug('Service Request', $debugData); |
||
43 | |||
44 | $data = $request->all(); |
||
45 | |||
46 | $postData = null; |
||
47 | |||
48 | if (isset($data['MMEX_Post'])) { |
||
49 | $postData = json_decode($data['MMEX_Post']); |
||
50 | } elseif (isset($data['postData'])) { |
||
51 | $postData = json_decode($data['postData']); |
||
52 | } |
||
53 | |||
54 | if ($postData) { |
||
55 | Log::debug('MmexController, $postData', [$postData]); |
||
56 | } |
||
57 | |||
58 | $function = $this->getFunction($data); |
||
59 | |||
60 | if ($function == Functions::CheckGuid) { |
||
61 | // TODO |
||
62 | return $this->returnSuccess(); |
||
63 | } |
||
64 | |||
65 | if ($function == Functions::CheckApiVersion) { |
||
66 | return $this->returnText(MmexConstants::$api_version); |
||
67 | } |
||
68 | |||
69 | if ($function == Functions::DownloadTransactions) { |
||
70 | $transactions = $this->mmexService->getTransactions($user); |
||
71 | |||
72 | $responseText = ''; |
||
73 | if ($transactions->count()) { |
||
74 | $result = fractal() |
||
75 | ->collection($transactions) |
||
76 | ->serializeWith(new MmexArraySerializer()) |
||
77 | ->transformWith(new TransactionTransformer()) |
||
78 | ->toArray(); |
||
79 | |||
80 | // encodes the array as it its (with it keys "0"=> {}, as needed by client) |
||
81 | $responseText = $this->toJson($result); |
||
82 | } |
||
83 | |||
84 | return $this->returnText($responseText); |
||
85 | } |
||
86 | |||
87 | if ($function == Functions::DonwloadAttachment) { |
||
88 | |||
89 | // is something like: Transaction_3_test-receipt-3.png |
||
90 | $fileName = $data['download_attachment']; |
||
91 | |||
92 | $attachment = $this->mmexService->getAttachment($user, $fileName); |
||
93 | |||
94 | // return file as download |
||
95 | $filePath = $attachment->getPath(); |
||
96 | |||
97 | $headers = [ |
||
98 | 'Content-Type' => '', |
||
99 | 'Cache-Control' => 'public', |
||
100 | 'Content-Description' => 'File Transfer', |
||
101 | 'Content-Disposition' => 'attachment; filename= '.$fileName, |
||
102 | 'Content-Transfer-Encoding' => 'binary', |
||
103 | ]; |
||
104 | |||
105 | return response()->file($filePath, $headers); |
||
106 | } |
||
107 | |||
108 | if ($function == Functions::DeleteBankAccounts) { |
||
109 | $this->mmexService->deleteAccounts($user); |
||
110 | |||
111 | return $this->returnSuccess(); |
||
112 | } |
||
113 | |||
114 | if ($function == Functions::ImportBankAccounts) { |
||
115 | $this->mmexService->importBankAccounts($user, $postData); |
||
116 | |||
117 | return $this->returnSuccess(); |
||
118 | } |
||
119 | |||
120 | if ($function == Functions::DeletePayees) { |
||
121 | $this->mmexService->deletePayees($user); |
||
122 | |||
123 | return $this->returnSuccess(); |
||
124 | } |
||
125 | |||
126 | if ($function == Functions::ImportPayees) { |
||
127 | $this->mmexService->importPayees($user, $postData); |
||
128 | |||
129 | return $this->returnSuccess(); |
||
130 | } |
||
131 | |||
132 | if ($function == Functions::DeleteCategories) { |
||
133 | $this->mmexService->deleteCategories($user); |
||
134 | |||
135 | return $this->returnSuccess(); |
||
136 | } |
||
137 | |||
138 | if ($function == Functions::ImportCategories) { |
||
139 | $this->mmexService->importCategories($user, $postData); |
||
140 | |||
141 | return $this->returnSuccess(); |
||
142 | } |
||
143 | |||
144 | if ($function == Functions::DeleteTransactions) { |
||
145 | $transactionId = $data['delete_group']; |
||
146 | $this->mmexService->deleteTransactions($user, $transactionId); |
||
147 | |||
148 | return $this->returnSuccess(); |
||
149 | } |
||
150 | |||
151 | return $data; |
||
152 | } |
||
153 | |||
218 |
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.