Test Failed
Push — dev6 ( fbdc57...e936d8 )
by Ron
17:43
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
     * TODO - This method can go away????
37
     */
38
    // public function show($id)
39
    // {
40
    //     return TechTip::where('tip_id', $id)->get();
41
    // }
42
43
    /**
44
     * Edit function will flag a Tech Tip as innapropriate
45
     */
46
    public function edit($id)
47
    {
48
        $comment = TechTipComment::find($id);
49
        $comment->update(['flagged' => true]);
50
51
        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

51
        event(new TechTipCommentFlaggedEvent(/** @scrutinizer ignore-type */ $comment));
Loading history...
52
        return TechTipComment::where('tip_id', $comment->tip_id)->with('User')->get();
53
    }
54
55
    /**
56
     * Update a Tech Tip Comment
57
     */
58
    public function update(UpdateCommentRequest $request, $id)
59
    {
60
        $comment = TechTipComment::find($id);
61
        $comment->update($request->only(['comment']));
62
        $comment->save();
63
64
        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

64
        event(new TechTipCommentUpdatedEvent(/** @scrutinizer ignore-type */ $comment));
Loading history...
65
        return TechTipComment::where('tip_id', $comment->tip_id)->with('User')->get();
66
    }
67
68
    /**
69
     * Delete the Tech Tip Comment
70
     */
71
    public function destroy($id)
72
    {
73
        $comment = TechTipComment::find($id);
74
        $this->authorize('delete', $comment);
75
        $comment->delete();
76
77
        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

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