| Total Complexity | 14 | 
| Total Lines | 167 | 
| Duplicated Lines | 0 % | 
| Coverage | 100% | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php  | 
            ||
| 12 | class CriteriaController extends Controller  | 
            ||
| 13 | { | 
            ||
| 14 | /**  | 
            ||
| 15 | * Converts a Criteria to the shape sent and recieved by the api.  | 
            ||
| 16 | *  | 
            ||
| 17 | * @param Criteria $model  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 18 | * @return void  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 19 | */  | 
            ||
| 20 | 6 | public function toApiArray(Criteria $model)  | 
            |
| 21 |     { | 
            ||
| 22 | 6 | return array_merge($model->toArray(), $model->getTranslationsArray());  | 
            |
| 23 | }  | 
            ||
| 24 | |||
| 25 | /**  | 
            ||
| 26 | * Get the set of criteria associated with a Job.  | 
            ||
| 27 | *  | 
            ||
| 28 | * @param JobPoster $jobPoster  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 29 | * @return \Illuminate\Http\Response  | 
            ||
| 30 | */  | 
            ||
| 31 | 1 | public function indexByJob(JobPoster $jobPoster)  | 
            |
| 32 |     { | 
            ||
| 33 | 1 | $toApiArray = array($this, 'toApiArray');  | 
            |
| 34 | 1 |         $criteriaAray = Criteria::where('job_poster_id', $jobPoster->id)->get()->map($toApiArray); | 
            |
| 35 | 1 | return response()->json($criteriaAray);  | 
            |
| 36 | }  | 
            ||
| 37 | |||
| 38 | /**  | 
            ||
| 39 | * Update the set of criteria associated with a Job.  | 
            ||
| 40 | *  | 
            ||
| 41 | * @param Request $request  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 42 | * @param JobPoster $jobPoster  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 43 | * @return \Illuminate\Http\Response  | 
            ||
| 44 | */  | 
            ||
| 45 | 5 | public function batchUpdate(Request $request, JobPoster $jobPoster)  | 
            |
| 82 | }  | 
            ||
| 83 | |||
| 84 | /**  | 
            ||
| 85 | * Save a new criteria and create a notification.  | 
            ||
| 86 | *  | 
            ||
| 87 | * @param Criteria $criteria  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 88 | * @return void  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 89 | */  | 
            ||
| 90 | 4 | protected function createCriteria(Criteria $criteria)  | 
            |
| 91 |     { | 
            ||
| 92 | 4 | $criteria->save();  | 
            |
| 93 | |||
| 94 | 4 | $notification = $this->makeAssessmentPlanNotification(  | 
            |
| 95 | 4 | 'CREATE',  | 
            |
| 96 | 4 | $criteria  | 
            |
| 97 | );  | 
            ||
| 98 | 4 | $notification->save();  | 
            |
| 99 | |||
| 100 | 4 | return $criteria;  | 
            |
| 101 | }  | 
            ||
| 102 | |||
| 103 | /**  | 
            ||
| 104 | * Update an existing Job Criteria and create a notification if necessary.  | 
            ||
| 105 | *  | 
            ||
| 106 | * @param \App\Models\Criteria $oldCriteria Existing Critera.  | 
            ||
| 107 | * @param mixed[] $newData Updated version of the Critera.  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 108 | * @return void  | 
            ||
| 109 | */  | 
            ||
| 110 | 3 | protected function updateCriteria(Criteria $oldCriteria, $newData): void  | 
            |
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 111 |     { | 
            ||
| 112 | // We only need to create a notification when the non-descriptive fields change  | 
            ||
| 113 | 3 | if ($oldCriteria->skill_level_id != $newData['skill_level_id']  | 
            |
| 114 | 3 | || $oldCriteria->skill_id != $newData['skill_id']  | 
            |
| 115 |         ) { | 
            ||
| 116 | 2 | $notification = $this->makeAssessmentPlanNotification(  | 
            |
| 117 | 2 | 'UPDATE',  | 
            |
| 118 | 2 | $oldCriteria,  | 
            |
| 119 | 2 | $newData['skill_id'],  | 
            |
| 120 | 2 | $newData['skill_level_id'],  | 
            |
| 121 | 2 | $newData['criteria_type_id']  | 
            |
| 122 | );  | 
            ||
| 123 | 2 | $notification->save();  | 
            |
| 124 | }  | 
            ||
| 125 | // Get just the data that can be changed  | 
            ||
| 126 | 3 | $fillableData = collect($newData)->except(['id', 'job_poster_id'])->toArray();  | 
            |
| 127 | 3 | $oldCriteria->fill($fillableData);  | 
            |
| 128 | 3 | $oldCriteria->save();  | 
            |
| 129 | 3 | }  | 
            |
| 130 | |||
| 131 | /**  | 
            ||
| 132 | * Delete existing Job Criteria and create a notification.  | 
            ||
| 133 | *  | 
            ||
| 134 | * @param \App\Models\Criteria $criteria Incoming Criteria.  | 
            ||
| 135 | * @return void  | 
            ||
| 136 | */  | 
            ||
| 137 | 2 | protected function deleteCriteria(Criteria $criteria): void  | 
            |
| 148 | 2 | }  | 
            |
| 149 | |||
| 150 | /**  | 
            ||
| 151 | * Create a new AssessmentPlanNotification for a modification to a Criteria  | 
            ||
| 152 | *  | 
            ||
| 153 | * @param string $type Can be CREATE, UPDATE or DELETE.  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 154 | * @param \App\Models\Criteria $criteria The Criteria (the OLD criteria if updating or deleting)  | 
            ||
| 
                                                                                                                                                        
                         2 ignored issues 
                            –
                            show
                         | 
                |||
| 155 | * @param integer|null $newSkillId Only used for UPDATE type notifications.  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 156 | * @param integer|null $newSkillLevelId Only used for UPDATE type notifications.  | 
            ||
| 
                                                                                                    
                         1 ignored issue 
                            –
                            show
                         | 
                |||
| 157 | * @param integer|null $newCriteriaTypeId Only used for UPDATE type notifications.  | 
            ||
| 158 | * @return \App\Models\AssessmentPlanNotification  | 
            ||
| 159 | */  | 
            ||
| 160 | 5 | protected function makeAssessmentPlanNotification(  | 
            |
| 181 |