Issues (166)

app/Http/Controllers/UsersController.php (12 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Validator;
7
use App\User;
8
use App\Http\Requests;
9
use App\Http\Controllers\Controller;
10
use Lubus\Constants\Status;
0 ignored issues
show
The type Lubus\Constants\Status 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...
11
12
class UsersController extends Controller
13
{
14
	/** 
15
     * Display a listing of the resource.
16
     *
17
     * @return Response
0 ignored issues
show
The type App\Http\Controllers\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
18
     */
19
    public function index()
20
    {
21
    	$users = user::excludeArchive()->paginate(10);
22
23
    	return view('users.index', compact('users'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('users.index', compact('users')) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
24
    }
25
26
     /**
27
     * Display the specified resource.
28
     *
29
     * @param  int  $id
30
     * @return Response
31
     */
32
    public function show()
33
    {
34
    	$user = user::findOrFail($id);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
35
36
    	return view('users.show', compact('user'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('users.show', compact('user')) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
37
    }
38
39
     /**
40
     * Show the form for creating a new resource.
41
     *
42
     * @return Response
43
     */
44
    public function create()
45
    {
46
    	return view('users.create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('users.create') returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
47
    }
48
    
49
     /**
50
     * Store a newly created resource in storage.
51
     *
52
     * @return Response
53
     */
54
    public function store(Request $request)
55
    {
56
        $this->validate($request, ['email' => 'unique:mst_users,email']);
57
58
        $user=array('name'=>$request->name,
59
                    'email'=> $request->email,
60
                    'photo'=> '',
61
                    'password' => bcrypt($request->password),
62
                    'status'=> $request->status);
63
        $user  = new User($user);
64
        $user->save();
65
66
        if($user->id)
67
        {
68
69
        $user->photo = \constFilePrefix::StaffPhoto. $user->id . '.jpg';
0 ignored issues
show
The property photo does not seem to exist on App\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
70
        $user->save();
71
        \Utilities::uploadFile($request,\constFilePrefix::StaffPhoto, $user->id,'photo',\constPaths::StaffPhoto);       
72
73
        flash()->success('User was successfully registered');
74
75
        return redirect('users'); 
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('users') returns the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
76
        }
77
78
        else
79
        {
80
            flash()->error('Error while user registration');
81
            return redirect('users');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('users') returns the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
82
        } 
83
    }
84
85
    public function edit($id)
86
    {
87
        $user=user::findOrFail($id);
88
89
        return view('users.edit', compact('user'));
90
    }
91
92
    public function update($id, Request $request)
93
    {
94
        $user=user::findOrFail($id);
95
96
        $user->name = $request->name;
97
        $user->email = $request->email;
98
99
        if($request->password !="")
100
        {
101
            $user->password = bcrypt($request->password);
102
        }
103
104
        $user->status = $request->status;
105
106
        $user->update();
107
        $user->photo = \constFilePrefix::staffPhoto. $user->id . '.jpg';
0 ignored issues
show
The constant constFilePrefix::staffPhoto was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
108
        $user->save();
109
110
        \Utilities::uploadFile($request,\constFilePrefix::staffPhoto, $user->id,'photo',\constPaths::staffPhoto);
0 ignored issues
show
The constant constPaths::staffPhoto was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
111
112
        flash()->success('User details was successfully updated');
113
        return redirect('users');
114
    }
115
116
    public function archive($id, Request $request)
0 ignored issues
show
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

116
    public function archive($id, /** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
117
    {
118
        $user=user::findOrFail($id);
119
        $user->status = \constStatus::Archive;
120
        $user->save();
121
        flash()->error('User was successfully deleted');
122
        return redirect('users');
123
    }
124
}
125