PasswordNotOld::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 View Code Duplication
class PasswordNotOld implements RuleInterface
10
{
11
    use RuleTrait;
12
13
    public function __construct()
14
    {
15
        $this->message = 'Podane hasło jest nieprawidłowe';
16
    }
17
18
    public function test($value)
19
    {
20
        $user = User::find($_SESSION['user']);
21
        
22
        if (!$user) {
23
            return false;
24
        }
25
        
26
        if (!password_verify($value, $user->password)) {
27
            return true;
28
        }
29
30
        return false;
31
    }
32
}
33