Completed
Pull Request — master (#14)
by
unknown
32:14 queued 17:14
created

NewPassword   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A passes() 0 8 2
A message() 0 4 1
1
<?php
2
3
namespace Spatie\ValidationRules\Rules;
4
5
use Illuminate\Support\Facades\Hash;
6
use Illuminate\Contracts\Validation\Rule;
7
use Illuminate\Contracts\Auth\Authenticatable;
8
9
final class NewPassword implements Rule
10
{
11
    private $user;
12
13
    public function __construct(Authenticatable $user = null)
14
    {
15
        $this->user = $user;
16
    }
17
18
    /**
19
     * Determine if the validation rule passes.
20
     *
21
     * @param  string  $attribute
22
     * @param  mixed  $value
23
     * @return bool
24
     */
25
    public function passes($attribute, $value)
26
    {
27
        if (! $this->user) {
28
            return true;
29
        }
30
31
        return ! Hash::check($value, $this->user->getAuthPassword());
32
    }
33
34
    /**
35
     * Get the validation error message.
36
     *
37
     * @return string
38
     */
39
    public function message()
40
    {
41
        return __('validationRules.new_password');
42
    }
43
}
44