Conditions | 4 |
Paths | 5 |
Total Lines | 34 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 4.0218 |
Changes | 4 | ||
Bugs | 1 | Features | 1 |
1 | <?php namespace Distilleries\Expendable\States; |
||
36 | 12 | public function postExport(Request $request) |
|
37 | { |
||
38 | |||
39 | 12 | $form = FormBuilder::create($this->export_form, [ |
|
40 | 12 | 'model' => $this->model |
|
41 | 9 | ]); |
|
42 | |||
43 | |||
44 | 12 | if ($form->hasError()) |
|
45 | 9 | { |
|
46 | 4 | return $form->validateAndRedirectBack(); |
|
47 | } |
||
48 | |||
49 | |||
50 | 8 | $data = $request->all(); |
|
51 | |||
52 | 8 | foreach ($data['range'] as $key => $date) |
|
53 | { |
||
54 | 8 | $data['range'][$key] = date('Y-m-d', strtotime($date)); |
|
55 | 6 | } |
|
56 | |||
57 | 8 | $result = $this->model->betweenCreate($data['range']['start'], $data['range']['end'])->get(); |
|
58 | |||
59 | 8 | if (!$result->isEmpty()) |
|
60 | 6 | { |
|
61 | 8 | $exporter = app($data['type']); |
|
62 | 8 | $file = $exporter->export($result->toArray(), $data['range']['start'] . ' ' . $data['range']['end']); |
|
63 | |||
64 | return $file; |
||
65 | } |
||
66 | |||
67 | return redirect()->to(action('\\' . get_class($this) . '@getExport')); |
||
68 | |||
69 | } |
||
70 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: