Total Complexity | 44 |
Total Lines | 326 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
Complex classes like BaseProductController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BaseProductController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class BaseProductController extends ExtendedBaseProductController |
||
14 | { |
||
15 | public function getMyUrl() |
||
26 | } |
||
27 | |||
28 | /* |
||
29 | * Get Product Qty if Product can be modified |
||
30 | */ |
||
31 | public function getProductQtyCheck($productid, $planid) |
||
32 | { |
||
33 | try { |
||
34 | $check = self::checkMultiProduct($productid); |
||
|
|||
35 | if ($check == true) { |
||
36 | $value = Product::find($productid)->planRelation->find($planid)->planPrice->first()->product_quantity; |
||
37 | $value = $value == null ? 1 : $value; |
||
38 | |||
39 | return "<div> |
||
40 | <label class='required'>"./* @scrutinizer ignore-type */ |
||
41 | \Lang::get('message.quantity')."</label> |
||
42 | <input type='text' name='quantity' class='form-control' id='quantity' value='$value'> |
||
43 | </div>"; |
||
44 | } |
||
45 | } catch (\Exception $ex) { |
||
46 | Bugsnag::notifyException($ex); |
||
47 | |||
48 | return $ex->getMessage(); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | /* |
||
53 | * Check whether Product is allowed for Increasing the Quantity fromAdmin Panel |
||
54 | * @param int $productid |
||
55 | * |
||
56 | * @return boolean |
||
57 | */ |
||
58 | public function checkMultiProduct(int $productid) |
||
69 | } |
||
70 | |||
71 | public function getAgentQtyCheck($productid, $planid) |
||
72 | { |
||
73 | try { |
||
74 | $check = self::checkMultiAgent($productid); |
||
75 | if ($check == true) { |
||
76 | $value = Product::find($productid)->planRelation->find($planid)->planPrice->first()->no_of_agents; |
||
77 | $value = $value == null ? 0 : $value; |
||
78 | |||
79 | return "<div> |
||
80 | <label class='required'>"./* @scrutinizer ignore-type */ |
||
81 | \Lang::get('message.agent')."</label> |
||
82 | <input type='text' name='agents' class='form-control' id='agents' value='$value'> |
||
83 | </div>"; |
||
84 | } |
||
85 | } catch (\Exception $ex) { |
||
86 | Bugsnag::notifyException($ex); |
||
87 | |||
88 | return $ex->getMessage(); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | /* |
||
93 | * Check whether No of the GAents can be modified or not fromAdmin Panel |
||
94 | * @param int $productid |
||
95 | * |
||
96 | * @return boolean |
||
97 | */ |
||
98 | public function checkMultiAgent(int $productid) |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Get the Subscription and Price Based on the Product Selected while generating Invoice (Admin Panel). |
||
113 | * |
||
114 | * @param int $productid |
||
115 | * @param Request $request |
||
116 | * |
||
117 | * @return [type] |
||
118 | */ |
||
119 | public function getSubscriptionCheck(int $productid, Request $request) |
||
151 | } |
||
152 | } |
||
153 | |||
154 | public function userDownload($uploadid, $userid, $invoice_number, $version_id = '') |
||
155 | { |
||
156 | try { |
||
157 | if (\Auth::user()->role != 'admin') { |
||
158 | if (\Auth::user()->id != $userid) { |
||
159 | throw new \Exception('This user has no permission for this action'); |
||
160 | } |
||
161 | } |
||
162 | $user = new \App\User(); |
||
163 | $user = $user->findOrFail($userid); |
||
164 | |||
165 | $invoice = new \App\Model\Order\Invoice(); |
||
166 | $invoice = $invoice->where('number', $invoice_number)->first(); |
||
167 | $this->checkSubscriptionExpiry($invoice); |
||
168 | if ($user && $invoice) { |
||
169 | if ($user->active == 1) { |
||
170 | $product_id = $invoice->order()->value('product'); |
||
171 | $name = Product::where('id', $product_id)->value('name'); |
||
172 | $invoice_id = $invoice->id; |
||
173 | $release = $this->downloadProduct($uploadid, $userid, $invoice_id, $version_id); |
||
174 | if (is_array($release) && array_key_exists('type', $release)) { |
||
175 | $release = $release['release']; |
||
176 | |||
177 | return view('themes.default1.front.download', compact('release')); |
||
178 | } else { |
||
179 | header('Content-type: Zip'); |
||
180 | header('Content-Description: File Transfer'); |
||
181 | header('Content-Disposition: attachment; filename='.$name.'.zip'); |
||
182 | header('Content-type: application/zip'); |
||
183 | header('Content-Length: '.filesize($release)); |
||
184 | readfile($release); |
||
185 | // ob_end_clean(); |
||
186 | // flush(); |
||
187 | } |
||
188 | } else { |
||
189 | return redirect()->back()->with('fails', \Lang::get('activate-your-account')); |
||
190 | } |
||
191 | } else { |
||
192 | throw new \Exception(\Lang::get('message.no_permission_for_action')); |
||
193 | } |
||
194 | } catch (\Exception $ex) { |
||
195 | app('log')->error($ex->getMessage()); |
||
196 | Bugsnag::notifyException($ex); |
||
197 | |||
198 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
199 | } |
||
200 | } |
||
201 | |||
202 | public function getRelease($owner, $repository, $order_id, $file) |
||
203 | { |
||
204 | if ($owner && $repository) {//If the Product is downloaded from Github |
||
205 | $github_controller = new \App\Http\Controllers\Github\GithubController(); |
||
206 | $relese = $github_controller->listRepositories($owner, $repository, $order_id); |
||
207 | |||
208 | return ['release'=>$relese, 'type'=>'github']; |
||
209 | } elseif ($file) { |
||
210 | //If the Product is Downloaded from FileSystem |
||
211 | $fileName = $file->file; |
||
212 | $path = Setting::find(1)->value('file_storage'); |
||
213 | // $relese = storage_path().'/products'.'//'.$fileName; //For Local Server |
||
214 | //$relese = '/home/faveo/products/'.$file->file; |
||
215 | $relese = $path.'/'.$file->file; |
||
216 | |||
217 | return $relese; |
||
218 | } |
||
219 | } |
||
220 | |||
221 | public function getReleaseAdmin($owner, $repository, $file) |
||
235 | } |
||
236 | } |
||
237 | |||
238 | public function downloadProductAdmin($id) |
||
258 | } |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Get Price For a Particular Plan Selected. |
||
263 | * |
||
264 | * get productid,userid,plan id as request |
||
265 | * |
||
266 | * @return json The final Price of the Prduct |
||
267 | */ |
||
268 | public function getPrice(Request $request) |
||
287 | } |
||
288 | } |
||
289 | |||
290 | public function updateVersionFromGithub($productid, $github_owner, $github_repository) |
||
302 | } |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * Check Whether No. of Agents Allowed or Product Qunatity on cart. |
||
307 | * |
||
308 | * @author Ashutosh Pathak <[email protected]> |
||
309 | * |
||
310 | * @date 2019-01-11T00:18:49+0530 |
||
311 | * |
||
312 | * @param int $productid |
||
313 | * |
||
314 | * @return bool |
||
315 | */ |
||
316 | public function allowQuantityOrAgent(int $productid) |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * Checks Permission for Incresing the no. of Agents/Quantity in Cart. |
||
325 | * |
||
326 | * |
||
327 | * @param int $productid The id of the Product added to the cart |
||
328 | * |
||
329 | * @return array The permissons for Agents and Quantity |
||
330 | */ |
||
331 | public function isAllowedtoEdit(int $productid) |
||
341 |