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

SetTechTipComments   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 28
ccs 10
cts 14
cp 0.7143
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteTipComment() 0 6 1
A createTipComment() 0 16 1
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