| Conditions | 4 |
| Paths | 5 |
| Total Lines | 34 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4.0466 |
| Changes | 0 | ||
| 1 | <?php namespace Distilleries\Expendable\States; |
||
| 36 | 8 | public function postExport(Request $request) |
|
| 37 | { |
||
| 38 | |||
| 39 | 8 | $form = FormBuilder::create($this->export_form, [ |
|
| 40 | 8 | 'model' => $this->model |
|
| 41 | ]); |
||
| 42 | |||
| 43 | |||
| 44 | 8 | if ($form->hasError()) |
|
| 45 | { |
||
| 46 | 4 | return $form->validateAndRedirectBack(); |
|
| 47 | } |
||
| 48 | |||
| 49 | |||
| 50 | 4 | $data = $request->all(); |
|
| 51 | |||
| 52 | 4 | foreach ($data['range'] as $key => $date) |
|
| 53 | { |
||
| 54 | 4 | $data['range'][$key] = date('Y-m-d', strtotime($date)); |
|
| 55 | } |
||
| 56 | |||
| 57 | 4 | $result = $this->model->betweenCreate($data['range']['start'], $data['range']['end'])->get(); |
|
| 58 | |||
| 59 | 4 | if (!$result->isEmpty()) |
|
| 60 | { |
||
| 61 | 4 | $exporter = app($data['type']); |
|
| 62 | 4 | $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: