| Conditions | 8 |
| Paths | 128 |
| Total Lines | 55 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 23 | public function process(?Domain $domain, Module $module, Request $request) |
||
| 24 | { |
||
| 25 | // Pre-process |
||
| 26 | $this->preProcess($domain, $module, $request); |
||
| 27 | |||
| 28 | // File name |
||
| 29 | $fileName = uctrans($module->name, $module).'_'.date('Ymd_His'); |
||
|
|
|||
| 30 | |||
| 31 | // File extension |
||
| 32 | $fileExtension = $request->input('extension') ?? 'xlsx'; |
||
| 33 | |||
| 34 | // Use special format for pdf file |
||
| 35 | $specialFormat = $fileExtension === 'pdf' ? \Maatwebsite\Excel\Excel::MPDF : null; |
||
| 36 | |||
| 37 | // Init export |
||
| 38 | $export = (new RecordsExport) |
||
| 39 | ->forDomain($domain) |
||
| 40 | ->forModule($module); |
||
| 41 | |||
| 42 | // With ID |
||
| 43 | if ($request->input('with_id') === '1') { |
||
| 44 | $export = $export->withId(); |
||
| 45 | } |
||
| 46 | |||
| 47 | // With timestamps |
||
| 48 | if ($request->input('with_timestamps') === '1') { |
||
| 49 | $export = $export->withTimestamps(); |
||
| 50 | } |
||
| 51 | |||
| 52 | // With descendants |
||
| 53 | if ($request->input('with_descendants') === '1') { |
||
| 54 | $export = $export->withDescendants(); |
||
| 55 | } |
||
| 56 | |||
| 57 | // With hidden columns |
||
| 58 | if ($request->input('with_hidden_columns') !== '1') { |
||
| 59 | $columns = json_decode($request->input('columns')); |
||
| 60 | $export = $export->withColumns($columns); |
||
| 61 | } |
||
| 62 | |||
| 63 | // With conditions |
||
| 64 | if ($request->input('with_conditions') === '1') { |
||
| 65 | // TODO: Build $conditions['search'] earlier in the export process to match filter format... |
||
| 66 | $conditions = ['search' => json_decode($request->input('conditions'))]; |
||
| 67 | $export = $export->withConditions($conditions); |
||
| 68 | } |
||
| 69 | |||
| 70 | // With order |
||
| 71 | if ($request->input('with_order') === '1') { |
||
| 72 | $order = json_decode($request->input('order')); |
||
| 73 | $export = $export->withOrder($order); |
||
| 74 | } |
||
| 75 | |||
| 76 | // Export records |
||
| 77 | return $export->download($fileName.'.'.$fileExtension, $specialFormat); |
||
| 78 | } |
||
| 80 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.