Passed
Push — dev6 ( d87223...fbdc57 )
by Ron
18:58
created

TechTipCommentsController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
c 2
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers\TechTips;
4
5
use Illuminate\Http\Request;
6
use App\Http\Controllers\Controller;
7
8
use App\Models\TechTip;
9
use App\Models\TechTipComment;
10
use App\Events\TechTips\TechTipCommentCreatedEvent;
11
use App\Events\TechTips\TechTipCommentDeletedEvent;
12
use App\Events\TechTips\TechTipCommentFlaggedEvent;
13
use App\Events\TechTips\TechTipCommentUpdatedEvent;
14
use App\Http\Requests\TechTips\TechTipCommentRequest;
15
use App\Http\Requests\TechTips\UpdateCommentRequest;
16
17
class TechTipCommentsController extends Controller
18
{
19
    /**
20
     * Store a newly created Tech Tip Comment
21
     */
22
    public function store(TechTipCommentRequest $request)
23
    {
24
        $comment = TechTipComment::create([
25
            'tip_id'  => $request->tip_id,
26
            'user_id' => $request->user()->user_id,
27
            'comment' => $request->comment,
28
        ]);
29
30
        event(new TechTipCommentCreatedEvent($comment));
31
        return TechTipComment::where('tip_id', $request->tip_id)->with('User')->get();
32
    }
33
34
    /**
35
     * Get the comments for a specific Tech Tip
36
     */
37
    public function show($id)
38
    {
39
        return TechTip::where('tip_id', $id)->get();
40
    }
41
42
    /**
43
     * Edit function will flag a Tech Tip as innapropriate
44
     */
45
    public function edit($id)
46
    {
47
        $comment = TechTipComment::find($id);
48
        $comment->update(['flagged' => true]);
49
50
        event(new TechTipCommentFlaggedEvent($comment));
1 ignored issue
show
Bug introduced by
It seems like $comment can also be of type null; however, parameter $comment of App\Events\TechTips\Tech...gedEvent::__construct() does only seem to accept App\Models\TechTipComment, maybe add an additional type check? ( Ignorable by Annotation )

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

50
        event(new TechTipCommentFlaggedEvent(/** @scrutinizer ignore-type */ $comment));
Loading history...
51
        return TechTipComment::where('tip_id', $comment->tip_id)->with('User')->get();
52
    }
53
54
    /**
55
     * Update a Tech Tip Comment
56
     */
57
    public function update(UpdateCommentRequest $request, $id)
58
    {
59
        $comment = TechTipComment::find($id);
60
        $comment->update($request->only(['comment']));
61
        $comment->save();
62
63
        event(new TechTipCommentUpdatedEvent($comment));
1 ignored issue
show
Bug introduced by
It seems like $comment can also be of type null; however, parameter $comment of App\Events\TechTips\Tech...tedEvent::__construct() does only seem to accept App\Models\TechTipComment, maybe add an additional type check? ( Ignorable by Annotation )

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

63
        event(new TechTipCommentUpdatedEvent(/** @scrutinizer ignore-type */ $comment));
Loading history...
64
        return TechTipComment::where('tip_id', $comment->tip_id)->with('User')->get();
65
    }
66
67
    /**
68
     * Delete the Tech Tip Comment
69
     */
70
    public function destroy($id)
71
    {
72
        $comment = TechTipComment::find($id);
73
        $this->authorize('delete', $comment);
74
        $comment->delete();
75
76
        event(new TechTipCommentDeletedEvent($comment));
1 ignored issue
show
Bug introduced by
It seems like $comment can also be of type null; however, parameter $comment of App\Events\TechTips\Tech...tedEvent::__construct() does only seem to accept App\Models\TechTipComment, maybe add an additional type check? ( Ignorable by Annotation )

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

76
        event(new TechTipCommentDeletedEvent(/** @scrutinizer ignore-type */ $comment));
Loading history...
77
        return TechTipComment::where('tip_id', $comment->tip_id)->with('User')->get();
78
    }
79
}
80