Completed
Push — master ( 324ac5...c1aece )
by ARCANEDEV
03:42
created

UpdatePasswordRequest::getValidatedData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Auth\Http\Requests\Admin\Profile;
2
3
use Arcanesoft\Auth\Http\Requests\FormRequest;
4
5
/**
6
 * Class     UpdatePasswordRequest
7
 *
8
 * @package  Arcanesoft\Auth\Http\Requests\Admin\Profile
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class UpdatePasswordRequest extends FormRequest
12
{
13
    /* -----------------------------------------------------------------
14
     |  Main Methods
15
     | -----------------------------------------------------------------
16
     */
17
    /**
18
     * Determine if the user is authorized to make this request.
19
     *
20
     * @return bool
21
     */
22
    public function authorize()
23
    {
24
        /** @var  \Arcanesoft\Contracts\Auth\Models\User  $user */
25
        $user = $this->route('auth_user');
26
27
        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
The method user does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
28
    }
29
30
    /**
31
     * Get the validation rules that apply to the request.
32
     *
33
     * @return array
34
     */
35
    public function rules()
36
    {
37
        return [
38
            'old_password' => ['required', 'string', 'min:8', 'different:password', 'user_password'],
39
            'password'     => ['required', 'string', 'min:8', 'different:old_password', 'confirmed'],
40
        ];
41
    }
42
43
    /**
44
     * Set custom messages for validator errors.
45
     *
46
     * @return array
47
     */
48
    public function messages()
49
    {
50
        return [
51
            'old_password.different' => trans('auth::profile.validation.password_different'),
52
            'password.different'     => trans('auth::profile.validation.password_different'),
53
        ];
54
    }
55
56
    /* -----------------------------------------------------------------
57
     |  Other Methods
58
     | -----------------------------------------------------------------
59
     */
60
61
    /**
62
     * Get the validated data.
63
     *
64
     * @return array
65
     */
66
    public function getValidatedData()
67
    {
68
        return $this->only(['password']);
69
    }
70
}
71