Passed
Push — master ( 1d6d9a...2a90e7 )
by Ron
02:47 queued 12s
created

SetTechTipComments::createTipComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 16
ccs 10
cts 10
cp 1
crap 1
rs 9.9666
1
<?php
2
3
namespace App\Domains\TechTips;
4
5
use Illuminate\Support\Facades\Log;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Notification;
8
9
use App\User;
10
use App\TechTips;
11
use App\TechTipComments;
12
13
use App\Http\Requests\TechTipNewCommentRequest;
14
15
use App\Notifications\NewTechTipComment;
16
17
class SetTechTipComments
18
{
19
    //  Add a comment to a Tech Tip
20 2
    public function createTipComment(TechTipNewCommentRequest $request)
21
    {
22 2
        TechTipComments::create([
23 2
            'tip_id'  => $request->tip_id,
24 2
            'user_id' => Auth::user()->user_id,
25 2
            'comment' => $request->comment,
26
        ]);
27
28
        //  Notify the Tech Tip Owner
29 2
        $ownerID = TechTips::find($request->tip_id)->user_id;
30 2
        $owner   = User::find($ownerID);
31
32 2
        Notification::send($owner, new NewTechTipComment(Auth::user()->full_name, $request->tip_id));
33
34 2
        Log::info('User '.Auth::user()->full_name.' commented on Tech Tip ID '.$request->tip_id.'.  Details - ', array($request));
35 2
        return true;
36
    }
37
38
    //  Remove a comment from a Tech Tip
39
    public function deleteTipComment($commentID)
40
    {
41
        TechTipComments::find($commentID)->delete();
42
43
        Log::notice('A Tech Tip Comment (id# '.$commentID.') was deleted by '.Auth::user()->full_name);
44
        return true;
45
    }
46
}
47