Conditions | 9 |
Paths | 8 |
Total Lines | 52 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
27 | public function exportToWord(Enrollment $enrollment) |
||
28 | { |
||
29 | App::setLocale(config('app.locale')); |
||
30 | $templateProcessor = new TemplateProcessor(storage_path('afsantiago/enrollment.docx')); |
||
31 | |||
32 | $templateProcessor->setValue('enrollment_date', $enrollment->date); |
||
33 | $templateProcessor->setValue('name', $enrollment->student_name); |
||
34 | |||
35 | $nif = $enrollment->student->idnumber ?: ''; |
||
36 | $phone = $enrollment->student->phone->count() > 0 && $enrollment->student->phone->first()->phone_number ? $enrollment->student->phone->first()->phone_number : ''; |
||
37 | $email = $enrollment->student->email ?: ''; |
||
38 | $address = $enrollment->student->address ?: ''; |
||
39 | $city = $enrollment->student->city ?: ''; |
||
40 | |||
41 | $templateProcessor->setValue('address', $address); |
||
42 | $templateProcessor->setValue('city', $city); |
||
43 | $templateProcessor->setValue('phone', $phone); |
||
44 | $templateProcessor->setValue('nif', $nif); |
||
45 | $templateProcessor->setValue('email', $email); |
||
46 | |||
47 | $templateProcessor->setValue('description', $this->utf8_for_xml($enrollment->course->name ?? '')); |
||
48 | $templateProcessor->setValue('start_date', $enrollment->course->formatted_start_date); |
||
49 | $templateProcessor->setValue('end_date', $enrollment->course->formatted_end_date); |
||
50 | $templateProcessor->setValue('volume', $enrollment->course->volume); |
||
51 | |||
52 | $table = new Table(['borderSize' => 8, |
||
53 | 'borderColor' => 'black', |
||
54 | 'cellMargin' => 80, |
||
55 | 'alignment' => JcTable::CENTER, |
||
56 | 'cellSpacing' => 50, |
||
57 | 'width' => 100 * 50, ]); |
||
58 | |||
59 | $firstRowStyle = ['bgColor' => 'd9d9d9']; |
||
60 | |||
61 | $table->addRow(500, $firstRowStyle); |
||
62 | $table->addCell(4000, $firstRowStyle)->addText(Str::upper(__('Due Date'))); |
||
|
|||
63 | $table->addCell(5000, $firstRowStyle)->addText(Str::upper(__('Total'))); |
||
64 | |||
65 | if ($enrollment->scheduledPayments->count() > 0) { |
||
66 | foreach ($enrollment->scheduledPayments as $payment) { |
||
67 | $table->addRow(500); |
||
68 | $table->addCell(4000)->addText($payment->date_for_humans, [], ['spaceAfter' => 0]); |
||
69 | $table->addCell(5000)->addText($payment->value_with_currency, [], ['spaceAfter' => 0]); |
||
70 | } |
||
71 | $templateProcessor->setComplexBlock('payments', $table); |
||
72 | } else { |
||
73 | $templateProcessor->setValue('payments', ''); |
||
74 | } |
||
75 | |||
76 | $path = $templateProcessor->save(); |
||
77 | |||
78 | return response()->download($path)->deleteFileAfterSend(true); |
||
79 | } |
||
81 |