Test Failed
Push — master ( fcc3b8...91cd3f )
by Yuvaraj
04:41
created

updateNewMemberJoinNotification()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 35
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 16
nc 2
nop 2
1
<?php
2
3
namespace LaravelRealtimeChat\Repositories\Team;
4
use App\Events\JoinNotificationEvenHandler;
0 ignored issues
show
Bug introduced by
The type App\Events\JoinNotificationEvenHandler 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...
5
class DbTeamRepository implements TeamRepository {
6
7
        /**
8
         * @param int $id channel_name_id
9
         * @return Arr returns array of teams aligned to user or admin
0 ignored issues
show
Bug introduced by
The type LaravelRealtimeChat\Repositories\Team\Arr 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...
10
         */
11
        public function getTeams($id) {//
12 View Code Duplication
                if (\Session::get("role") == 1) {
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...
13
                        $teams = \DB::table('channels')
14
                                            ->select('team_channels.id', 'channels.channel_name', 'team_channels.channel_view_name', 'channels.author_id', "team_channels.created_at", 'team_channels.team_channel_id','team_heads.user_id')
15
                                            ->leftJoin('team_channels', 'channels.id', '=', 'team_channels.channel_name_id')
16
                                              ->leftJoin('team_heads', 'team_heads.team_id', '=', 'team_channels.id')
17
                                            ->where('team_channels.id', '!=', '')
18
                                            ->where('channels.id', '=', $id)->distinct()->get();
19
                }
20
                else {
21
                        $teams = \DB::table('team_channels')
22
                                            ->select('team_channels.channel_view_name', 'team_channels.team_channel_id', 'team_channels.id', 'team_channels.created_at','team_heads.user_id')
23
                                            ->leftJoin('team_channel_users', 'team_channel_users.team_channel_name_id', '=', 'team_channels.id')
24
                                                ->leftJoin('team_heads', 'team_heads.team_id', '=', 'team_channels.id')         
25
                                               ->where('team_channel_users.user_id', '=', \Auth::user()->id)->distinct()->get();
26
                }
27
28
                return $teams;
29
        }
30
        
31
        /**
32
         * @param int $id team_id
33
         * @return Arr returns array of members aligned to a team
34
         */
35
        public function getMembers($id) {
36
                $teamId      = $id;
37
                $teamArr     = array();
38
                $teamMembers = \DB::table('users')
39
                                    ->select('users.first_name', 'users.id', 'users.last_name')
40
                                    ->leftJoin('team_channel_users', 'team_channel_users.user_id', '=', 'users.id')
41
                                    ->where('team_channel_users.team_channel_name_id', '=', $teamId)->get();
42
                foreach ($teamMembers as $memeber) {
43
                        $teamArr[] = $memeber["first_name"] . "_" . $memeber["last_name"] . "_" . $memeber["id"];
44
                }
45
                return $teamArr;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $teamArr returns the type array|string[] which is incompatible with the documented return type LaravelRealtimeChat\Repositories\Team\Arr.
Loading history...
46
        }
47
48
        public function getTeamDecodedId($id) {
49
                $team = \DB::table('team_channels')
50
                                    ->select('id')
51
                                    ->where('team_channel_id', '=', $id)->first();
52
                return $team['id'];
53
        }
54
        
55
         public function getTeamName($id) {
56
                $team = \DB::table('team_channels')
57
                                    ->select('team_channels.channel_view_name',\DB::raw('CONCAT(users.first_name, " ", users.last_name) AS full_name'))
58
                                    ->leftJoin('team_heads', 'team_heads.team_id', '=', 'team_channels.id')
59
                                    ->leftJoin('users', 'users.id', '=', 'team_heads.user_id')
60
                                    ->where('team_channels.id', '=', $id)->first();
61
                return $team['channel_view_name']."_".$team['full_name'];
62
        }
63
        
64
        public function updateTeamName($id) {
65
        $name = \Input::get('name');
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...
66
        if(empty($name))
67
            return "empty";
68
        try {
69
            //validate for duplicates
70
            $data = \DB::table('team_channels')
71
                            ->select('team_channels.channel_view_name')
72
                            ->where('channel_view_name', '=', $name)->first();
73
            if (count($data) == 0) {
74
                //perform update
75
                \DB::table('team_channels')
76
                        ->where('id', $id)
77
                        ->update(['channel_view_name' => $name]);
78
            } else
79
                return "exists";
80
        } catch (\Exception $e) {
81
            //coudnt update
82
            return "false";
83
        }
84
        return "true";
85
    }
86
87
    public function updateTeamHead($id) {
88
        $userId = \Input::get('userId');
89
        if (empty($userId))
90
            return "empty";
91
        try {
92
93
            //perform update
94
            \DB::table('team_heads')
95
                    ->where('team_id', $id)
96
                    ->update(['user_id' => $userId]);
97
        } catch (\Exception $e) {
98
            //coudnt update
99
            return "false";
100
        }
101
        return "true";
102
    }
103
    
104
    public function updateNewMemberJoinNotification($team_id,$user_id){
105
       
106
        /**
107
         * 
108
         * Get all team details where the user is a memeber
109
         * 
110
         * 
111
         * 
112
         */
113
        $teamArr = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $teamArr is dead and can be removed.
Loading history...
114
        
115
       $details= $this->getUserDetails($user_id);
116
      
117
            $teamMembers =\DB::table('users')
118
                            ->select('users.first_name','users.last_name', 'users.id','team_channels.channel_view_name','team_channels.team_channel_id','team_channels.id as team_id_decoded')
119
                            ->leftJoin('team_channel_users', 'team_channel_users.user_id', '=', 'users.id')
120
                    ->leftJoin('team_channels', 'team_channel_users.team_channel_name_id', '=', 'team_channels.id')
121
                            ->where('team_channel_users.team_channel_name_id', '=', $team_id)->get();
122
123
            foreach ($teamMembers as $memeber) {
124
                //insert notification
125
                 $lastId = \DB::table('invitation_notification')->insertGetId(
0 ignored issues
show
Unused Code introduced by
The assignment to $lastId is dead and can be removed.
Loading history...
126
                        ['team_id' => $team_id, "team_user" => $memeber["id"],'new_user'=>$user_id]
127
                );
128
                //Publish data to redis
129
                $channelId = $memeber["id"] . "_" . $memeber["team_channel_id"];
0 ignored issues
show
Unused Code introduced by
The assignment to $channelId is dead and can be removed.
Loading history...
130
131
                $teamChannelId = $memeber["team_channel_id"];
132
               
133
                $data = array(
134
                    'room' =>$memeber["id"] . "_" . $memeber["team_channel_id"],
135
                    'message' => array('new_user_id'=>$user_id,'new_user_channel_id' => $user_id."_".$teamChannelId,'user_id' =>$memeber["id"] ,'name'=>$details['first_name']." ".$details['last_name'],'team_name'=>$memeber['channel_view_name'],'team_id'=>$memeber['team_id_decoded'])
136
                );
137
//                 print_r($data);
138
               \Event::fire(\JoinNotificationEventHandler::EVENT, array(json_encode($data)));
139
            }
140
        
141
   
142
    }
143
    
144
    
145
      public function getUserDetails($user_id){
146
             $details =\DB::table('users')
147
              ->select('users.first_name','users.last_name')
148
                     ->where('id', '=', $user_id)   
149
                     ->first();
150
             return $details;
151
      }
152
153
}