UpdateUserRequest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 9 1
A authorize() 0 9 1
1
<?php
2
3
namespace App\Containers\User\UI\API\Requests;
4
5
use App\Ship\Parents\Requests\Request;
6
7
/**
8
 * Class UpdateUserRequest.
9
 *
10
 * @author Mahmoud Zalt <[email protected]>
11
 */
12
class UpdateUserRequest extends Request
13
{
14
15
    /**
16
     * Define which Roles and/or Permissions has access to this request.
17
     *
18
     * @var  array
19
     */
20
    protected $access = [
21
        'permissions' => 'update-users',
22
        'roles'       => '',
23
    ];
24
25
    /**
26
     * Id's that needs decoding before applying the validation rules.
27
     *
28
     * @var  array
29
     */
30
    protected $decode = [
31
        'id',
32
    ];
33
34
    /**
35
     * Defining the URL parameters (`/stores/999/items`) allows applying
36
     * validation rules on them and allows accessing them like request data.
37
     *
38
     * @var  array
39
     */
40
    protected $urlParameters = [
41
        'id',
42
    ];
43
44
    /**
45
     * @return  array
46
     */
47
    public function rules()
48
    {
49
        return [
50
            'email'    => 'email|unique:users,email',
51
            'id'       => 'required|exists:users,id',
52
            'password' => 'min:6|max:40',
53
            'name'     => 'min:2|max:50',
54
        ];
55
    }
56
57
    /**
58
     * @return  bool
59
     */
60
    public function authorize()
61
    {
62
        // is this an admin who has access to permission `update-users`
63
        // or the user is updating his own object (is the owner).
64
65
        return $this->check([
66
            'hasAccess|isOwner',
67
        ]);
68
    }
69
}
70