Issues (56)

app/Http/Controllers/ApiUserController.php (5 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\DestroyUser;
6
use App\Http\Requests\ListUser;
7
use App\Http\Requests\ShowUser;
8
use App\Http\Requests\StoreUser;
9
use App\Http\Requests\UpdateUser;
10
use App\User;
11
use Illuminate\Http\Request;
12
13
class ApiUserController extends Controller
14
{
15
    public function index(ListUser $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

15
    public function index(/** @scrutinizer ignore-unused */ ListUser $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...
16
    {
17
        return User::all();
18
    }
19
20
    public function show(ShowUser $user)
21
    {
22
        return $user;
23
    }
24
25
    //La funció del request s'anomena injeccio de dependències.
26
    public function store(StoreUser $request)
27
    {
28
        $request->validate([
0 ignored issues
show
The call to Illuminate\Foundation\Http\FormRequest::validate() has too many arguments starting with array('name' => 'require...d' => 'required|min:6'). ( Ignorable by Annotation )

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

28
        $request->/** @scrutinizer ignore-call */ 
29
                  validate([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
29
           'name'     => 'required|max:255',
30
           'username' => 'sometimes|required|max:255|unique:users',
31
           'email'    => 'required|email|max:255|unique:users',
32
           'password' => 'required|min:6',
33
        ]);
34
35
        $user = User::create([
36
               'name'     => $request->name,
37
               'username' => $request->username,
38
               'email'    => $request->email,
39
               'password' => bcrypt($request->password),
40
            ]);
41
42
        return $user;
43
    }
44
45
    public function destroy(DestroyUser $user)
46
    {
47
        //el User $user és equivalent a $user = User::findOrFail($id)
48
49
        $user->delete();
0 ignored issues
show
The method delete() does not exist on App\Http\Requests\DestroyUser. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

49
        $user->/** @scrutinizer ignore-call */ 
50
               delete();
Loading history...
50
51
        return $user;
52
    }
53
54
    public function update(UpdateUser $request, User $user)
55
    {
56
        $request->validate([
0 ignored issues
show
The call to Illuminate\Foundation\Http\FormRequest::validate() has too many arguments starting with array('name' => 'required'). ( Ignorable by Annotation )

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

56
        $request->/** @scrutinizer ignore-call */ 
57
                  validate([

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
57
            'name' => 'required',
58
        ]);
59
60
        $user->name = $request->name;
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __set, consider adding a @property annotation.
Loading history...
61
        $user->save();
62
63
        return $user;
64
    }
65
}
66