Completed
Push — master ( f40498...e3ae3a )
by ARCANEDEV
03:17
created

UpdatePasswordRequest::authorize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4286
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Auth\Http\Requests\Backend\Profile;
2
3
use Arcanesoft\Auth\Bases\FormRequest;
4
5
/**
6
 * Class     UpdatePasswordRequest
7
 *
8
 * @package  Arcanesoft\Auth\Http\Requests\Backend\Profile
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class UpdatePasswordRequest extends FormRequest
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * The Validation rules.
19
     *
20
     * @var array
21
     */
22
    protected $rules = [
23
        'old_password'          => 'required|min:8|different:password|user_password',
24
        'password'              => 'required|min:8|different:old_password|confirmed',
25
        'password_confirmation' => 'required|min:8',
26
    ];
27
28
    /**
29
     * @var \Arcanesoft\Contracts\Auth\Models\User $user
30
     */
31
    protected $user;
32
33
    /* ------------------------------------------------------------------------------------------------
34
     |  Main Functions
35
     | ------------------------------------------------------------------------------------------------
36
     */
37
    /**
38
     * Determine if the user is authorized to make this request.
39
     *
40
     * @return bool
41
     */
42
    public function authorize()
43
    {
44
        /** @var \Arcanesoft\Contracts\Auth\Models\User $user */
45
        $user = $this->route('user_id');
46
47
        return $user->id === auth()->user()->id;
0 ignored issues
show
Bug introduced by
Accessing id on the interface Arcanesoft\Contracts\Auth\Models\User suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
48
    }
49
50
    /**
51
     * Get the validation rules that apply to the request.
52
     *
53
     * @return array
54
     */
55
    public function rules()
56
    {
57
        return $this->rules;
58
    }
59
60
    /**
61
     * Set custom messages for validator errors.
62
     *
63
     * @return array
64
     */
65
    public function messages()
66
    {
67
        return [
68
            'old_password.different' => 'The old and new passwords must be different.',
69
            'password.different'     => 'The old and new passwords must be different.',
70
        ];
71
    }
72
}
73