Passed
Push — feature/screening-plan-redux ( d5330b...8fda69 )
by Chris
08:20
created

AssessmentController::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Assessment;
6
use App\Models\Criteria;
7
use App\Models\Lookup\AssessmentType;
8
9
use Illuminate\Http\Request;
10
11
class AssessmentController extends Controller
12
{
13
    /**
14
     * Store a newly created resource in storage.
15
     *
16
     * @param  \Illuminate\Http\Request $request
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
17
     * @return mixed
18
     */
19
    public function store(Request $request)
20
    {
21
        try {
22
            $criterion_id = (int)$request->json('criterion_id');
23
            $assessment_type_id = (int)$request->json('assessment_type_id');
24
            Criteria::findOrFail($criterion_id);
25
            AssessmentType::findOrFail($assessment_type_id);
26
        } catch (\Exception $e) {
27
            abort(401);
28
        }
29
30
        $assessment = new Assessment([
31
            'criterion_id' => $criterion_id,
32
            'assessment_type_id' => $assessment_type_id
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $assessment_type_id does not seem to be defined for all execution paths leading up to this point.
Loading history...
33
        ]);
34
        $assessment->save();
35
        $assessment->refresh();
36
37
        return [
38
            'message' => "Successfully created assessment $assessment->id"
39
        ];
40
    }
41
42
    /**
43
     * Display the specified resource.
44
     *
45
     * @param  \App\Assessment $assessment
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
46
     * @return mixed
47
     */
48
    public function show(Assessment $assessment)
49
    {
50
        return $assessment->toArray();
51
    }
52
53
    /**
54
     * Update the specified resource in storage.
55
     *
56
     * @param  \Illuminate\Http\Request $request
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
57
     * @param  \App\Assessment          $assessment
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
58
     * @return mixed
59
     */
60
    public function update(Request $request, Assessment $assessment)
61
    {
62
        try {
63
            $criterion_id = (int)$request->json('criterion_id');
64
            $assessment_type_id = (int)$request->json('assessment_type_id');
65
            Criteria::findOrFail($criterion_id);
66
            AssessmentType::findOrFail($assessment_type_id);
67
        } catch (\Exception $e) {
68
            abort(401);
69
        }
70
71
        $assessment->criterion_id = $criterion_id;
72
        $assessment->assessment_type_id = $assessment_type_id;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $assessment_type_id does not seem to be defined for all execution paths leading up to this point.
Loading history...
73
        $assessment->save();
74
75
        return [
76
            'message' => "Successfully updated assessment $assessment->id"
77
        ];
78
    }
79
80
    /**
81
     * Remove the specified resource from storage.
82
     *
83
     * @param  \App\Assessment $assessment
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
84
     * @return mixed
85
     */
86
    public function destroy(Assessment $assessment)
87
    {
88
        $assessment->delete();
89
90
        return [
91
            'message' => "Successfully deleted assessment $assessment->id"
92
        ];
93
    }
94
}
95