Passed
Push — dev5 ( 8206b9...846a42 )
by Ron
07:15
created

DashboardController::delNotification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.2109

Importance

Changes 0
Metric Value
cc 2
eloc 8
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 15
ccs 5
cts 8
cp 0.625
crap 2.2109
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Module;
0 ignored issues
show
Bug introduced by
The type Module was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use App\TechTips;
7
use App\FileLinks;
8
use Carbon\Carbon;
9
use App\TechTipFavs;
10
use App\CustomerFavs;
11
use Illuminate\Support\Facades\Log;
12
use Illuminate\Support\Facades\Auth;
13
14
class DashboardController extends Controller
15
{
16 20
    public function __construct()
17
    {
18
        //  Only authorized users have access to these pages
19 20
        $this->middleware('auth');
20 20
    }
21
22
    //  Dashboard is the Logged In User home landing page
23 2
    public function index()
24
    {
25 2
        $custFavs    = CustomerFavs::where('user_id', Auth::user()->user_id)->with('Customers')->get();
26 2
        $tipFavs     = TechTipFavs::where('user_id', Auth::user()->user_id)->with('TechTips')->get();
27 2
        $tips30Days  = TechTips::where('created_at', '>', Carbon::now()->subDays(30))->count();
28 2
        $tipsTotal   = TechTips::all()->count();
29 2
        $activeLinks = FileLinks::where('user_id', Auth::user()->user_id)->where('expire', '>', Carbon::now())->count();
30 2
        $totalLinks  = FileLinks::where('user_id', Auth::user()->user_id)->count();
31
32 2
        return view('dashboard', [
33 2
           'custFavs'    => $custFavs,
34 2
           'tipFavs'     => $tipFavs,
35 2
           'tips30'      => $tips30Days,
36 2
           'tipsAll'     => $tipsTotal,
37 2
           'activeLinks' => $activeLinks,
38 2
           'totalLinks'  => $totalLinks,
39
//            'modules'       => $modules
40
        ]);
41
    }
42
43
    //  About page
44
    public function about()
45
    {
46
        exec('git symbolic-ref HEAD', $output);
47
        $t = explode('/', $output[0]);
48
        $branch = end($t) === 'master' ? 'latest' : end($t);
49
50
        return view('about', [
51
            'branch' => $branch
52
        ]);
53
    }
54
55
    //  Get the users notifications
56
    public function getNotifications()
57
    {
58
        return Auth::user()->notifications;
59
    }
60
61
    //  Mark a notification as read
62 4
    public function markNotification($id)
63
    {
64 4
        $notification = Auth::user()->notifications()->where('id', $id)->where('notifiable_id', Auth::user()->user_id)->first();
65 4
        if(!$notification)
66
        {
67 4
            return abort(404);
68
        }
69
        $notification->markAsRead();
70
71
        return response()->json(['success' => true]);
72
    }
73
74
    //  Deelte a user notification
75 4
    public function delNotification($id)
76
    {
77 4
        $notification = Auth::user()->notifications()->where('id', $id)->where('notifiable_id', Auth::user()->user_id)->first();
78 4
        if($notification)
79
        {
80
            $notification->delete();
81
            Log::info('Notification ID-'.$id.' deleted for User ID-'.Auth::user()->user_id);
82
        }
83
        else
84
        {
85 4
            Log::notice('Notification ID-'.$id.' not found for user ID-'.Auth::user()->user_id);
86 4
            return abort(404);
1 ignored issue
show
Bug introduced by
Are you sure the usage of abort(404) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
87
        }
88
89
        return response()->json(['success' => true]);
90
    }
91
}
92