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

UserValidator::validateUserPassword()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4286
cc 2
eloc 5
nc 2
nop 4
crap 6
1
<?php namespace Arcanesoft\Auth\Validators;
2
3
use Illuminate\Support\Facades\Hash;
4
5
/**
6
 * Class     UserValidator
7
 *
8
 * @package  Arcanesoft\Auth\Validators
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class UserValidator
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Validation Functions
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Validate the user current/old password.
19
     *
20
     * @param  string                            $attribute
21
     * @param  string                            $value
22
     * @param  array                             $parameters
23
     * @param  \Illuminate\Validation\Validator  $validator
24
     *
25
     * @return bool
26
     */
27
    public function validateUserPassword($attribute, $value, $parameters, $validator)
28
    {
29
        unset($attribute, $parameters, $validator);
30
31
        if (auth()->guest()) {
32
            return false;
33
        }
34
35
        return Hash::check($value, auth()->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?

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...
36
    }
37
}
38