Passed
Push — feature/screening-plan-notific... ( f17be6 )
by Tristan
22:12 queued 13:01
created

AssessmentPlanNotificationController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 27
dl 0
loc 76
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A destroy() 0 7 1
A show() 0 4 1
A index() 0 2 1
A update() 0 28 3
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\JobPoster;
6
use App\Models\Lookup\AssessmentType;
7
8
use Illuminate\Http\Request;
9
use Illuminate\Http\Response;
10
use App\Models\AssessmentPlanNotification;
11
12
class AssessmentPlanNotificationController extends Controller
13
{
14
    /**
15
     * Display a list of the specified resource
16
     *
17
     * @param  \Illuminate\Http\Request $request Incoming request.
18
     * @return mixed
19
     */
20
    public function index(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

20
    public function index(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
    }
23
24
    /**
25
     * Display the specified resource.
26
     *
27
     * @param  \App\Models\AssessmentPlanNotification $assessmentPlanNotification Incoming object.
28
     * @return mixed
29
     */
30
    public function show(AssessmentPlanNotification $assessmentPlanNotification)
31
    {
32
        $this->authorize('view', $assessmentPlanNotification);
33
        return $assessmentPlanNotification->toArray();
34
    }
35
36
    /**
37
     * Update the specified resource in storage.
38
     *
39
     * @param  \Illuminate\Http\Request        $request             Incoming request.
2 ignored issues
show
Coding Style introduced by
Expected 15 spaces after parameter type; 8 found
Loading history...
Coding Style introduced by
Expected 20 spaces after parameter name; 13 found
Loading history...
40
     * @param  \App\Models\AssessmentPlanNotification $assessmentPlanNotification Incoming object.
41
     * @throws \InvalidArgumentException For missing $question.
42
     * @return mixed
43
     */
44
    public function update(Request $request, AssessmentPlanNotification $assessmentPlanNotification)
45
    {
46
        $this->authorize('update', $assessmentPlanNotification);
47
        try {
48
            $job_poster_id = (int)$request->json('job_poster_id');
49
            $assessment_type_id = (int)$request->json('assessment_type_id');
50
            $question = $request->json('question');
51
52
            JobPoster::findOrFail($job_poster_id);
53
            AssessmentType::findOrFail($assessment_type_id);
54
55
            if (empty($question)) {
56
                throw new \InvalidArgumentException('Question is required.');
57
            }
58
59
            $assessmentPlanNotification->job_poster_id = $job_poster_id;
60
            $assessmentPlanNotification->assessment_type_id = $assessment_type_id;
0 ignored issues
show
Bug introduced by
The property assessment_type_id does not seem to exist on App\Models\AssessmentPlanNotification. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
61
            $assessmentPlanNotification->question = $question;
0 ignored issues
show
Bug introduced by
The property question does not seem to exist on App\Models\AssessmentPlanNotification. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
62
            $assessmentPlanNotification->save();
63
        } catch (\Exception $e) {
64
            return response()->json([
65
                'error' => $e->getMessage()
66
            ], 400);
67
        }
68
69
        return [
70
            'success' => "Successfully updated rating guide question $assessmentPlanNotification->id",
71
            'rating_guide_question' => $assessmentPlanNotification->toArray(),
72
        ];
73
    }
74
75
    /**
76
     * Remove the specified resource from storage.
77
     *
78
     * @param  \App\Models\AssessmentPlanNotification $assessmentPlanNotification Incoming object.
79
     * @return mixed
80
     */
81
    public function destroy(AssessmentPlanNotification $assessmentPlanNotification)
82
    {
83
        $this->authorize('delete', $assessmentPlanNotification);
84
        $assessmentPlanNotification->delete();
85
86
        return [
87
            'success' => "Successfully deleted rating guide question $assessmentPlanNotification->id"
88
        ];
89
    }
90
}
91