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

UserProfileController::deactivateAccount()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 14
nc 3
nop 0
1
<?php
2
3
class UserProfileController extends AuthController {
4
   
5 View Code Duplication
    public function userProfile() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
6
        if (Auth::user()) {
7
8
            //   $email = Auth::user()->email;
9
            $userDetails = DB::table('users')->select('*')->where('id', Auth::user()->id)->get();
10
            foreach ($userDetails as $key => $value) {
11
                $userDetailsArray = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $userDetailsArray is dead and can be removed.
Loading history...
12
                $userDetailsArray = $value;
13
            }
14
           // print_r($userDetailsArray);
15
             $data['userDetailsArray']=$userDetailsArray;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
Comprehensibility Best Practice introduced by
The variable $userDetailsArray seems to be defined by a foreach iteration on line 10. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
16
            return View::make('layouts/profile')->with("userDetailsArray", $userDetailsArray);
17
        }
18
19
        return Redirect::route('main');
20
    }
21
22 View Code Duplication
    public function viewProfile($userId) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
23
        if (Auth::user()) {
24
25
            //   $email = Auth::user()->email;
26
            $userDetails = DB::table('users')->select('*')->where('id', $userId)->get();
27
            foreach ($userDetails as $key => $value) {
28
                $userDetailsArray = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $userDetailsArray is dead and can be removed.
Loading history...
29
                $userDetailsArray = $value;
30
            }
31
            // print_r($userDetailsArray);
32
            // $data['userDetailsArray']=$userDetailsArray;
33
            return View::make('layouts/profile')->with("userDetailsArray", $userDetailsArray);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $userDetailsArray seems to be defined by a foreach iteration on line 27. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
34
        }
35
36
        return Redirect::route('main');
37
    }
38
39
    public function updateProfile() {
40
41
        DB::table('users')->where('id', Auth::user()->id)->update(array(
42
            'summary' => Input::get('summary'), 'first_name' => Input::get('first_name'), 'birthday' => Input::get('birthday'), 'gender' => Input::get('gender')
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...
43
            , 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'contact' => Input::get('contact')
44
                )
45
        );
46
          return Redirect::to('/view_profile/'.Auth::user()->id);
47
    }
48
49
    public function updateProfilePicture() {
50
        $userProfile = DB::table('users')->select('profile_pic')->where('id', Auth::user()->id)->get();
51
        foreach ($userProfile as $key => $value) {
52
                $userDetailsArray = $value;
53
            }
54
            @unlink('fusionmate/public/plugins/profile_pics/'.$userDetailsArray['profile_pic']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

54
            /** @scrutinizer ignore-unhandled */ @unlink('fusionmate/public/plugins/profile_pics/'.$userDetailsArray['profile_pic']);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
Comprehensibility Best Practice introduced by
The variable $userDetailsArray seems to be defined by a foreach iteration on line 51. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
55
        
56
        // Build the input for our validation
57
        $input = array('image' => Input::file('avatar'));
58
59
        // Within the ruleset, make sure we let the validator know that this
60
        // file should be an image
61
        $rules = array(
62
            'image' => 'image|required'
63
        );
64
        // Now pass the input and rules into the validator
65
        $validator = Validator::make($input, $rules);
66
67
        // Check to see if validation fails or passes
68
        if ($validator->fails()) {
69
            // Redirect with a helpful message to inform the user that 
70
            // the provided file was not an adequate type
71
//            return Redirect::back()->withErrors(['Error: The provided file was not an image', 'Error: The provided file was not an image']);
72
             return Redirect::back()->withErrors($validator);
73
            //print_r('Error: The provided file was not an image');
74
            // return Redirect::to('/')->with('message', 'Error: The provided file was not an image');
75
        } else {
76
            $file = Input::file('avatar');
77
            
78
            $file->move('fusionmate/public/plugins/profile_pics', $file->getClientOriginalName());
79
80
            $imgPath = $file->getClientOriginalName();
81
            $imagePath = $imgPath;
82
            DB::table('users')->where('id', Auth::user()->id)->update(array(
83
                'profile_pic' => $imagePath
84
                    )
85
            );
86
            return Redirect::to('/view_profile/'.Auth::user()->id);
87
            // Actually go and store the file now, then inform 
88
            // the user we successfully uploaded the file they chose
89
            //return Redirect::to('/')->with('message', 'Success: File upload was successful');
90
        }
91
    }
92
    public function settings() {
93
        if (Auth::user()) {
94
            return View::make('templates/settings/password_settings');
95
        }
96
97
        return Redirect::route('main');
98
    }
99
    
100
     public function updatePassword() {
101
          $input = Input::all();
102
           $rules = array(
103
                       'current_password' => 'required',
104
105
             'password' => 'required|min:6|regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{1,}$/',
106
        'password_confirm' => 'required|same:password'
107
        );
108
           
109
        // Now pass the input and rules into the validator
110
        $validator = Validator::make($input, $rules);
111
        // Check to see if validation fails or passes
112
        if ($validator->fails()) {
113
         
114
             return Redirect::back()->withErrors($validator);
115
        } else {
116
         $password=  Hash::make(Input::get('new_password'));
117
        DB::table('users')->where('id', Auth::user()->id)->update(array(
118
                'password' => $password
119
                    )
120
            );
121
        }
122
          return Redirect::to('/settings/');
123
    }
124
    
125
    function deactivateAccount(){
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
126
         if (Auth::user()) {            
127
        $loggedInUser=Auth::user()->id;
128
        $userProfile = DB::table('users')->select('profile_pic')->where('id', Auth::user()->id)->get();
129
        foreach ($userProfile as $key => $value) {
130
                $userDetailsArray = $value;
131
            }
132
        @unlink('fusionmate/public/plugins/profile_pics/'.$userDetailsArray['profile_pic']);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $userDetailsArray seems to be defined by a foreach iteration on line 129. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

132
        /** @scrutinizer ignore-unhandled */ @unlink('fusionmate/public/plugins/profile_pics/'.$userDetailsArray['profile_pic']);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
133
        DB::table('team_channel_users')->where('user_id', '=', $loggedInUser)->delete();
134
        DB::table('team_conversations')->where('user_id', '=', $loggedInUser)->delete();
135
        DB::table('team_conversations_read_status')->where('user_id', '=', $loggedInUser)->delete();
136
        DB::table('team_heads')->where('user_id', '=', $loggedInUser)->delete();
137
        DB::table('login_status')->where('user_id', '=', $loggedInUser)->delete();
138
        DB::table('user_roles')->where('user_id', '=', $loggedInUser)->delete();
139
        $affected = DB::table('users')->where('id', '=', $loggedInUser)->delete();
0 ignored issues
show
Unused Code introduced by
The assignment to $affected is dead and can be removed.
Loading history...
140
//        @unlink('fusionmate/public/plugins/userUploads/' . $userDetailsArray['profile_pic']);
141
            return Redirect::route('main');
142
         }
143
                 
144
145
             
146
    }
147
}
148