UpdatePasswordRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 61
ccs 0
cts 23
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 7 1
A rules() 0 7 1
A messages() 0 7 1
A getValidatedData() 0 4 1
1
<?php namespace Arcanesoft\Auth\Http\Requests\Admin\Profile;
2
3
use Arcanesoft\Auth\Http\Requests\FormRequest;
4
use Arcanesoft\Auth\Rules\OldPasswordRule;
5
6
/**
7
 * Class     UpdatePasswordRequest
8
 *
9
 * @package  Arcanesoft\Auth\Http\Requests\Admin\Profile
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class UpdatePasswordRequest extends FormRequest
13
{
14
    /* -----------------------------------------------------------------
15
     |  Main Methods
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * Determine if the user is authorized to make this request.
21
     *
22
     * @return bool
23
     */
24
    public function authorize()
25
    {
26
        /** @var  \Arcanesoft\Contracts\Auth\Models\User  $user */
27
        $user = $this->route('auth_user');
28
29
        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...
30
    }
31
32
    /**
33
     * Get the validation rules that apply to the request.
34
     *
35
     * @return array
36
     */
37
    public function rules()
38
    {
39
        return [
40
            'old_password' => ['required', 'string', 'min:8', 'different:password', new OldPasswordRule(auth()->user())],
0 ignored issues
show
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...
41
            'password'     => ['required', 'string', 'min:8', 'different:old_password', 'confirmed'],
42
        ];
43
    }
44
45
    /**
46
     * Set custom messages for validator errors.
47
     *
48
     * @return array
49
     */
50
    public function messages()
51
    {
52
        return [
53
            'old_password.different' => trans('auth::profile.validation.password_different'),
54
            'password.different'     => trans('auth::profile.validation.password_different'),
55
        ];
56
    }
57
58
    /* -----------------------------------------------------------------
59
     |  Other Methods
60
     | -----------------------------------------------------------------
61
     */
62
63
    /**
64
     * Get the validated data.
65
     *
66
     * @return array
67
     */
68
    public function getValidatedData()
69
    {
70
        return $this->only(['password']);
71
    }
72
}
73