PasswordNotOld   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 91.67 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A test() 13 14 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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