RatingGuideAnswerController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 71
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 4 1
A destroy() 0 7 1
A store() 0 11 1
A update() 0 12 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\RatingGuideAnswer;
6
use App\Http\Requests\UpdateRatingGuideAnswer;
7
use App\Http\Requests\StoreRatingGuideAnswer;
8
9
class RatingGuideAnswerController extends Controller
10
{
11
    /**
12
     * Store a newly created resource in storage.
13
     *
14
     * @param  \App\Requests\StoreRatingGuideAnswer $request Incoming request.
15
     * @throws \InvalidArgumentException For missing $expected_answer.
16
     * @return mixed
17
     */
18
    public function store(StoreRatingGuideAnswer $request)
19
    {
20
        // Authorization handled by the FormRequest.
21
        // Data validation handled by this line.
22
        $data = $request->validated();
23
        $ratingGuideAnswer = new RatingGuideAnswer($data);
24
        $ratingGuideAnswer->save();
25
26
        return [
27
            'success' => "Successfully created rating guide answer $ratingGuideAnswer->id",
28
            'rating_guide_answer' => $ratingGuideAnswer->toArray(),
29
        ];
30
    }
31
32
    /**
33
     * Display the specified resource.
34
     *
35
     * @param  \App\Models\RatingGuideAnswer $ratingGuideAnswer Incoming object.
36
     * @return mixed
37
     */
38
    public function show(RatingGuideAnswer $ratingGuideAnswer)
39
    {
40
        $this->authorize('view', $ratingGuideAnswer);
41
        return $ratingGuideAnswer->toArray();
42
    }
43
44
    /**
45
     * Update the specified resource in storage.
46
     *
47
     * @param  \App\Requests\UpdateRatingGuideAnswer $request           Incoming request.
48
     * @param  \App\Models\RatingGuideAnswer         $ratingGuideAnswer Incoming object.
49
     * @throws \InvalidArgumentException For empty $expected_answer.
50
     * @return mixed
51
     */
52
    public function update(UpdateRatingGuideAnswer $request, RatingGuideAnswer $ratingGuideAnswer)
53
    {
54
        // Authorization handled by the FormRequest.
55
        // Data validation handled by this line.
56
        $data = $request->validated();
57
58
        $ratingGuideAnswer->fill($data);
59
        $ratingGuideAnswer->save();
60
        $ratingGuideAnswer->refresh();
61
        return [
62
            'success' => "Successfully updated rating guide answer $ratingGuideAnswer->id",
63
            'rating_guide_answer' => $ratingGuideAnswer->toArray(),
64
        ];
65
    }
66
67
    /**
68
     * Remove the specified resource from storage.
69
     *
70
     * @param  \App\Models\RatingGuideAnswer $ratingGuideAnswer Incoming object.
71
     * @return mixed
72
     */
73
    public function destroy(RatingGuideAnswer $ratingGuideAnswer)
74
    {
75
        $this->authorize('delete', $ratingGuideAnswer);
76
        $ratingGuideAnswer->delete();
77
78
        return [
79
            'success' => "Successfully deleted rating guide answer $ratingGuideAnswer->id"
80
        ];
81
    }
82
}
83