Conditions | 11 |
Paths | 13 |
Total Lines | 38 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
42 | public function storeEntry($input) |
||
43 | { |
||
44 | if ($this->form['actions']['store'] == 'true' || $this->form['actions']['store'] == true) { |
||
45 | $entry = new FormEntry(); |
||
46 | $entry->slug = $input->get('_form_slug'); |
||
47 | $json = []; |
||
48 | foreach ($this->form['fields'] as $fieldKey => $fieldValue) { |
||
49 | if ($fieldValue['type'] !== 'file') { |
||
50 | $json[$fieldKey] = $input->get($fieldKey); |
||
51 | } |
||
52 | } |
||
53 | if ($this->form['files'] == 'true') { |
||
54 | foreach ($this->form['fields'] as $fieldKey => $fieldValue) { |
||
55 | if ($fieldValue['type'] == 'file') { |
||
56 | if ($input->hasFile($fieldKey)) { |
||
57 | $avatar = $input->file($fieldKey); |
||
58 | $random = str_random(8); |
||
|
|||
59 | $filename = time().'_'.$random.'.'.$avatar->getClientOriginalExtension(); |
||
60 | if (!file_exists(public_path('/files/uploads/'))) { |
||
61 | mkdir(public_path('/files/uploads/'), 0777, true); |
||
62 | } |
||
63 | $avatar->move(public_path('/files/uploads/'), $filename); |
||
64 | $filepath = '/files/uploads/'.$filename; |
||
65 | } else { |
||
66 | $filepath = null; |
||
67 | } |
||
68 | $json[$fieldKey] = $filepath; |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | $entry->entry = $json; |
||
73 | if ($entry->save()) { |
||
74 | return $entry; |
||
75 | } else { |
||
76 | return 'error'; |
||
77 | } |
||
78 | } else { |
||
79 | return 'pass'; |
||
80 | } |
||
164 |