PasswordController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 23.81 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 0
cbo 1
dl 5
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getChangePassword() 0 4 1
A postChangePassword() 5 13 2

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\Controllers\Auth;
4
5
use App\Controllers\Controller;
6
7
class PasswordController extends Controller
8
{
9
    public function getChangePassword($request, $response)
10
    {
11
        return $this->view->render($response, 'auth/password/change.twig');
12
    }
13
14
    public function postChangePassword($request, $response)
15
    {
16 View Code Duplication
        if ($this->validator->validatePasswordChangeForm($request)->getErrorsCount() > 0) {
17
            $_SESSION['errors'] = $this->validator->getErrors();
18
            return $response->withRedirect($this->router->pathFor('auth.password.change'));
19
        }
20
21
        $this->auth->user()->setPassword($request->getParam('password1'));
22
23
        $this->flash->addMessage('success', 'Hasło zostało zmienione');
24
25
        return $response->withRedirect($this->router->pathFor('auth.password.change'));
26
    }
27
}
28