NotificationController   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 20 %

Importance

Changes 0
Metric Value
wmc 9
dl 16
loc 80
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B update_status() 16 30 5
B unread_notifications() 0 46 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class NotificationController extends BaseController {
4
5
    public function unread_notifications() {
6
        $type = Input::get('data'); //type to indicate whether global,task or message notification
0 ignored issues
show
Bug introduced by
The type Input 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...
7
        /*
8
         * get notofications,task notifications,global notifications contents ...
9
         */
10
        if ($type == "messages") {
11
            $unReadMessages = DB::table('messages')
12
                            ->select(DB::raw('count(from_user_id) as fromCount'), 'personal_conversations.*','team_channels.id as team_id', 'messages.*', 'users_from.first_name as from_first_name', 'users_from.first_name as from_last_name')
13
                            ->leftJoin('personal_conversations', 'messages.id', '=', 'personal_conversations.message_id')
14
                               ->leftJoin('team_channels', 'team_channels.id', '=', 'personal_conversations.team_channel_id')
15
                            ->leftJoin('users as users_from', 'users_from.id', '=', 'personal_conversations.from_user_id')
16
                            ->where('personal_conversations.read_status', '=', 1)
17
                            ->where('personal_conversations.to_user_id', '=', Auth::user()->id)->groupBy('from_user_id')->orderBy('messages.id', 'desc')->get();
18
            $unReadMessages = array_reverse($unReadMessages);
19
20
            $data = array($unReadMessages, "type" => $type);
21
        }
22
23
        if ($type == "general") {
24
            $unReadGeneralMessages = DB::table('team_conversations_read_status')
25
                            ->select(DB::raw('count(team_conversations_read_status.message_id) as messageCount'), 'team_channels.channel_view_name', 'team_channels.id')
26
                            ->leftJoin('team_channels', 'team_channels.id', '=', 'team_conversations_read_status.team_channel_id')
27
                            ->where('team_conversations_read_status.user_id', '=', Auth::user()->id)
28
                    ->where('team_conversations_read_status.read_status', '=', 1)
29
                    ->groupBy('team_channels.channel_view_name')->orderBy('team_conversations_read_status.message_id', 'desc')->get();
30
            $unReadGeneralMessages = array_reverse($unReadGeneralMessages);
31
32
            $data = array($unReadGeneralMessages, "type" => $type);
33
        }
34
        
35
        if ($type == "join") {
36
            $unReadJoinMessages = DB::table('invitation_notification')
37
                            ->select(DB::raw('count(invitation_notification.new_user) as userCount'), 'team_channels.channel_view_name', 'team_channels.team_channel_id', 'users.first_name', 'users.last_name', 'users.id as user_id', 'team_channels.id as team_id')
38
                            ->leftJoin('team_channels', 'team_channels.id', '=', 'invitation_notification.team_id')
39
                            ->leftJoin('users', 'users.id', '=', 'invitation_notification.new_user')
40
                            ->where('invitation_notification.team_user', '=', Auth::user()->id)
41
                             ->where('invitation_notification.new_user', '!=', Auth::user()->id)
42
                            ->where('invitation_notification.read_status', '=', 1)
43
                            ->groupBy('invitation_notification.new_user')
44
                            ->orderBy('invitation_notification.created_at', 'desc')->get();
45
            $unReadJoinMessages = array_reverse($unReadJoinMessages);
46
47
            $data = array($unReadJoinMessages, "type" => $type);
48
        }
49
50
        return View::make('templates/notification_content')->with("data", $data);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $data does not seem to be defined for all execution paths leading up to this point.
Loading history...
51
    }
52
53
    public function update_status() {
54
        $type = Input::get('data'); //type to indicate whether global,task or message notification
55
56
        switch ($type) {
57
            case "messages" : $fromUserId = Input::get('fromUserId');
58
                $toUserId = Input::get('toUserId');
59
                if ($type == "messages") {
60
                    DB::table('personal_conversations')
61
                            ->where('from_user_id', $fromUserId)
62
                            ->where('to_user_id', $toUserId)
63
                            ->update(array('read_status' => 0));
64
                }
65
                break;
66 View Code Duplication
            case "general":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
                $teamId = explode("_",Input::get('teamId'));
68
                
69
                DB::table('team_conversations_read_status')
70
                        ->where('user_id', Auth::user()->id)
71
                        ->where('team_channel_id', $teamId[1])
72
                        ->update(array('read_status' => 0));
73
                break;
74
            
75 View Code Duplication
                case "join":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
                $teamId = explode("_",Input::get('teamId'));
77
                
78
                DB::table('invitation_notification')
79
                        ->where('team_user', Auth::user()->id)
80
                        ->where('team_id', $teamId[1])
81
                        ->where('new_user', $teamId[0])
82
                        ->update(array('read_status' => 0));
83
        }
84
    }
85
86
}
87