PasswordValid   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A test() 0 15 3
1
<?php
2
3
namespace App\Validation\Rules;
4
5
use Albert221\Validation\Rule\RuleInterface;
6
use Albert221\Validation\Rule\RuleTrait as RuleTrait;
7
use App\Models\User;
8
9
class PasswordValid implements RuleInterface
10
{
11
    use RuleTrait;
12
13
    protected $email;
14
15
    public function __construct($email)
16
    {
17
        $this->message = 'Podane hasło jest nieprawidłowe';
18
        $this->email = $email;
19
    }
20
21
    public function test($value)
22
    {
23
        $user = User::where('email', $this->email)->first();
24
        
25
        if (!$user) {
26
            $this->message = 'Wypełnij poprawnie adres email';
27
            return false;
28
        }
29
        
30
        if (password_verify($value, $user->password)) {
31
            return true;
32
        }
33
34
        return false;
35
    }
36
}
37