GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 568257...f78015 )
by Alireza
18s queued 10s
created

ProfileController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 0
loc 64
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getEdit() 0 21 6
A postEdit() 0 39 4
1
<?php
2
namespace Serverfireteam\Panel;
3
4
use Illuminate\Routing\Controller;
5
use Illuminate\Support\Facades\Input;
6
use Illuminate\Support\Facades\File;
7
8
class ProfileController extends Controller {
9
10
    public function getEdit() {
11
12
        $admin = Admin::find(\Auth::guard('panel')->user()->id);
13
14
        $demo = false;
15
        if (\Config::get('panel.demo') == true) {
16
            $demo = true;
17
        }
18
19
        if (!$demo && request()->has('del_picture')){
20
            $file = $admin->getAdminPicture();
21
            //dd(public_path($file));
22
            if (!empty($file) && File::exists(public_path($file))){
23
                File::delete(public_path($file));
24
            }
25
            $admin->updateAdminPicture('');
26
            return \Redirect::to(request()->path());
27
        }
28
29
        return \View('panelViews::editProfile')->with('admin', $admin)->with('demo_status', $demo);
30
    }
31
32
    public function postEdit() {
33
34
        $demo = false;
35
        if (\Config::get('panel.demo') == true) {
36
            $demo = true;
37
        }
38
39
        $admin  = Admin::find(\Auth::guard('panel')->user()->id);
40
        $inputs = Input::all();
41
        request()->validate([
42
            'picture' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
43
        ]);
44
        // Check if a profile image has been uploaded
45
        if (request()->has('picture')) {
46
            // Get image file
47
            $image = request()->file('picture');
48
            // Make a image name based on user name and current timestamp
49
            $name = str_slug(request()->input('first_name')).'_'.str_slug(request()->input('last_name')).'_'.time();
0 ignored issues
show
Deprecated Code introduced by
The function str_slug() has been deprecated with message: Str::slug() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
50
            // Define folder path
51
            $folder = '/uploads/panel_avatars/';
52
            // Make a file path where image will be stored [ folder path + file name + file extension]
53
            $filePath = $folder . $name. '.' . $image->getClientOriginalExtension();
54
            // Upload image
55
            $name = !empty($name) ? $name : str_random(25);
0 ignored issues
show
Deprecated Code introduced by
The function str_random() has been deprecated with message: Str::random() should be used directly instead. Will be removed in Laravel 5.9.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
56
            $file = $image->move(public_path($folder), $name.'.'.$image->getClientOriginalExtension());
0 ignored issues
show
Unused Code introduced by
$file is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
58
            // Set user profile image path in database to filePath
59
            $admin->updateAdminPicture($filePath);
60
        }
61
        //dd($inputs['picture']);
62
        $admin->update($inputs);
63
        $admin->save();
64
        return \View('panelViews::editProfile')->with(
65
            array(
66
                'admin'   	  => $admin,
67
                'message'	  => \Lang::get('panel::fields.successfullEditProfile'),
68
                'demo_status'  => $demo)
69
        );
70
    }
71
}
72