Test Failed
Branch dev5 (4ce0ff)
by Ron
06:19
created

DashboardController::markNotification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 2
cp 0
crap 6
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\TechTipFavs;
7
use App\CustomerFavs;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Log;
10
use Illuminate\Support\Facades\Auth;
11
use Illuminate\Support\Facades\Gate;
12
13
use Zip;
14
use Carbon\Carbon;
15
16
//use Nwidart\Modules;
17
use Mail;
18
use App\Mail\InitializeUser;
19
20
use App\TechTips;
21
use App\FileLinks;
22
// use Carbon\Carbon;
23
24
25
26
27
class DashboardController extends Controller
28
{
29
    public function __construct()
30
    {
31
        //  Only authorized users have access to these pages
32
        $this->middleware('auth');
33
    }
34
35
    //  Dashboard is the Logged In User home landing page
36
    public function index()
37
    {
38
        //  Get the users Customer bookmarks
39
    //    $custFavs = CustomerFavs::where('user_id', Auth::user()->user_id)
40
    //        ->LeftJoin('customers', 'customer_favs.cust_id', '=', 'customers.cust_id')
41
    //        ->get();
42
//        //  Get the users Tech Tip bookmarks
43
//        $tipFavs = TechTipFavs::where('tech_tip_favs.user_id', Auth::user()->user_id)
44
//            ->LeftJoin('tech_tips', 'tech_tips.tip_id', '=', 'tech_tip_favs.tip_id')
45
//            ->get();
46
47
        $custFavs    = CustomerFavs::where('user_id', Auth::user()->user_id)->with('Customers')->get();
48
        $tipFavs     = TechTipFavs::where('user_id', Auth::user()->user_id)->with('TechTips')->get();
49
        $tips30Days  = TechTips::where('created_at', '>', Carbon::now()->subDays(30))->count();
50
        $tipsTotal   = TechTips::all()->count();
51
        $activeLinks = FileLinks::where('user_id', Auth::user()->user_id)->where('expire', '>', Carbon::now())->count();
52
        $totalLinks  = FileLinks::where('user_id', Auth::user()->user_id)->count();
53
54
55
        // return $tipFavs;
56
57
        return view('dashboard', [
58
           'custFavs'    => $custFavs,
59
           'tipFavs'     => $tipFavs,
60
           'tips30'      => $tips30Days,
61
           'tipsAll'     => $tipsTotal,
62
           'activeLinks' => $activeLinks,
63
           'totalLinks'  => $totalLinks,
64
//            'notifications' => $notifications->toArray(),
65
//            'modules'       => $modules
66
        ]);
67
    }
68
69
    //  About page
70
    public function about()
71
    {
72
        exec('git symbolic-ref HEAD', $output);
73
        $t = explode('/', $output[0]);
74
        $branch = end($t) === 'master' ? 'latest' : end($t);
75
76
        return view('about', [
77
            'branch' => $branch
78
        ]);
79
    }
80
81
    //  Get the users notifications
82
    public function getNotifications()
83
    {
84
        return Auth::user()->notifications;
85
    }
86
87
    //  Mark a notification as read
88
    public function markNotification($id)
89
    {
90
        $notification = Auth::user()->notifications()->where('id', $id)->where('notifiable_id', Auth::user()->user_id)->first();
91
        if(!$notification)
92
        {
93
            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...
94
        }
95
        $notification->markAsRead();
96
97
        return response()->json(['success' => true]);
98
    }
99
100
    //  Deelte a user notification
101
    public function delNotification($id)
102
    {
103
        $notification = Auth::user()->notifications()->where('id', $id)->where('notifiable_id', Auth::user()->user_id)->first();
104
        if($notification)
105
        {
106
            $notification->delete();
107
            Log::info('Notification ID-'.$id.' deleted for User ID-'.Auth::user()->user_id);
108
        }
109
        else
110
        {
111
            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...
112
            Log::notice('Notification ID-'.$id.' not found for user ID-'.Auth::user()->user_id);
0 ignored issues
show
Unused Code introduced by
Illuminate\Support\Facad...\Auth::user()->user_id) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
113
        }
114
115
        return response()->json(['success' => true]);
116
    }
117
}
118