HomeController::showWelcome()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 51
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.4109
c 0
b 0
f 0
cc 3
eloc 24
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
class HomeController extends BaseController {
4
5
    /*
6
    |--------------------------------------------------------------------------
7
    | Default Home Controller
8
    |--------------------------------------------------------------------------
9
    |
10
    | You may wish to use controllers instead of, or in addition to, Closure
11
    | based routes. That's great! Here is an example controller method to
12
    | get you started. To route to this controller, just add the route:
13
    |
14
    |    Route::get('/', 'HomeController@showWelcome');
15
    |
16
     */
17
18
    public function showWelcome()
19
    {
20
        
21
         if (Auth::user()) {
22
23
            //   $email = Auth::user()->email;
24
            $userDetails = DB::table('users')->select('*')->where('id', Auth::user()->id)->get();
25
            foreach ($userDetails as $key => $value) {
26
                $userDetailsArray = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $userDetailsArray is dead and can be removed.
Loading history...
27
                $userDetailsArray = $value;
28
            }
29
           // print_r($userDetailsArray);
30
           
31
//             $data['userDetailsArray']=$userDetailsArray;
32
           
33
        }
34
        /*
35
         * get notofications,task notifications,global notifications ...
36
         */
37
         $countUnreadMessages = DB::table('personal_conversations')
38
                ->select(DB::raw('count(read_status) as unread_count'))
39
                
40
                ->where('read_status','=',1)
41
                 ->where('to_user_id','=',Auth::user()->id)->first();
42
         
43
          $countUnreadGeneralMessages = DB::table('team_conversations_read_status')
44
                ->select(DB::raw('count(read_status) as unread_count'))
45
                
46
                ->where('read_status','=',1)
47
                 ->where('user_id','=',Auth::user()->id)->first();
48
          
49
          $countUnreadJoinMessages = DB::table('invitation_notification')
50
                ->select(DB::raw('count(read_status) as unread_count'))
51
                
52
                ->where('read_status','=',1)
53
                   
54
                     ->where('invitation_notification.new_user', '!=', Auth::user()->id)
55
                 ->where('team_user','=',Auth::user()->id)->first();
56
         /*
57
          * pass each notifcation count in array
58
          */
59
        
60
         $data=array(
61
             
62
                            "unreadMessageCount"=>$countUnreadMessages["unread_count"],
63
                            "userDetailsArray"=>$userDetailsArray,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $userDetailsArray does not seem to be defined for all execution paths leading up to this point.
Loading history...
64
                            "unreadGeneralMessageCount"=>$countUnreadGeneralMessages["unread_count"],
65
                            "unreadJoinMessageCount"=>$countUnreadJoinMessages["unread_count"],
66
                           
67
                    );
68
        return View::make('templates/home')->with("data",$data);
69
    }
70
71
}
72