PasswordNotOld::test()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 13
Ratio 92.86 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 13
loc 14
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
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