CurrentPassword   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 33
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A passes() 0 4 2
A message() 0 3 1
1
<?php
2
3
namespace Ikechukwukalu\Sanctumauthstarter\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Hash;
8
9
class CurrentPassword implements Rule
0 ignored issues
show
Deprecated Code introduced by
The interface Illuminate\Contracts\Validation\Rule has been deprecated: see ValidationRule ( Ignorable by Annotation )

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

9
class CurrentPassword implements /** @scrutinizer ignore-deprecated */ Rule

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
10
{
11
    /**
12
     * Create a new rule instance.
13
     *
14
     * @return void
15
     */
16
    public function __construct()
17
    {
18
        //
19
    }
20
21
    /**
22
     * Determine if the validation rule passes.
23
     *
24
     * @param  string  $attribute
25
     * @param  mixed  $value
26
     * @return bool
27
     */
28
    public function passes($attribute, $value)
29
    {
30
        $user = Auth::user();
31
        return Hash::check($value, $user->password) || is_null($user->password);
0 ignored issues
show
Bug introduced by
Accessing password on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
32
    }
33
34
    /**
35
     * Get the validation error message.
36
     *
37
     * @return string
38
     */
39
    public function message()
40
    {
41
        return trans('sanctumauthstarter::passwords.wrong');
42
    }
43
}
44