Passed
Push — dev5 ( dcc882...87417d )
by Ron
06:13
created

DashboardController::delNotification()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.3149

Importance

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