| Conditions | 14 |
| Paths | 12 |
| Total Lines | 74 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 210 |
| 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 |
||
| 58 | $this->authorize('create', SkillDeclaration::class); |
||
| 59 | |||
| 60 | $user = $request->user(); |
||
| 61 | $applicant = $user->applicant; |
||
| 62 | |||
| 63 | //Get the default claim status id |
||
| 64 | $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
||
| 65 | |||
| 66 | // Create a new Skill Declaration |
||
| 67 | // But don't save, as it hasn't been validated yet |
||
| 68 | $skillDeclaration = new SkillDeclaration(); |
||
| 69 | $skillDeclaration->applicant_id = $applicant->id; |
||
| 70 | $skillDeclaration->skill_id = $request->input('skill_id'); |
||
| 71 | $skillDeclaration->skill_status_id = $claimedStatusId; |
||
| 72 | |||
| 73 | //Update variable fields in skill declaration |
||
| 74 | return $this->updateSkillDeclaration($request, $skillDeclaration); |
||
|
1 ignored issue
–
show
|
|||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Update the particular skill declaration in storage. |
||
| 79 | * |
||
| 80 | * @param \Illuminate\Http\Request $request |
||
| 81 | * @param \App\Models\SkillDeclaration $skillDeclaration |
||
| 82 | * @return \Illuminate\Http\Response |
||
| 83 | */ |
||
| 84 | public function update(Request $request, SkillDeclaration $skillDeclaration) |
||
| 85 | { |
||
| 86 | $this->authorize('update', $skillDeclaration); |
||
| 87 | |||
| 88 | return $this->updateSkillDeclaration($request, $skillDeclaration); |
||
|
1 ignored issue
–
show
|
|||
| 89 | } |
||
| 90 | |||
| 91 | protected function updateSkillDeclaration(Request $request, SkillDeclaration $skillDeclaration) |
||
| 92 | { |
||
| 93 | //Fill variable values |
||
| 94 | $skillDeclaration->fill([ |
||
| 95 | 'description' => $request->input('description'), |
||
| 96 | 'skill_level_id' => $request->input('skill_level_id'), |
||
| 97 | ]); |
||
| 98 | |||
| 99 | //Validate before saving |
||
| 100 | $validator = new SkillDeclarationValidator($request->user()->applicant); |
||
| 101 | $validator->validate($skillDeclaration); |
||
| 102 | |||
| 103 | //Save this skill declaration |
||
| 104 | $skillDeclaration->save(); |
||
| 105 | |||
| 106 | //Attach relatives |
||
| 107 | $referenceIds = $this->getRelativeIds($request->input(), 'references'); |
||
| 108 | $skillDeclaration->references()->sync($referenceIds); |
||
| 109 | |||
| 110 | $sampleIds = $this->getRelativeIds($request->input(), 'samples'); |
||
| 111 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 112 | |||
| 113 | // $skillDeclaration->save(); |
||
| 114 | |||
| 115 | // If an ajax request, return the new object |
||
| 116 | if($request->ajax()) { |
||
| 117 | $skillDeclaration->load('references'); |
||
| 118 | $skillDeclaration->load('work_samples'); |
||
| 119 | $skillDeclaration->load('skill'); |
||
| 120 | $skillDeclaration->load('skill_status'); |
||
| 121 | return $skillDeclaration->toJson(); |
||
| 122 | } |
||
| 123 | |||
| 124 | return redirect()->back(); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Delete the particular skill declaration in storage. |
||
| 129 | * |
||
| 130 | * @param \Illuminate\Http\Request $request |
||
| 131 | * @param \App\Models\SkillDeclaration $skillDeclaration |
||
| 132 | * @return \Illuminate\Http\Response |
||
| 147 |