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

NewPassword::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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