Test Failed
Push — master ( 390c0f...bea1ad )
by Alexey
05:07
created

ChangePassword   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 33
Duplicated Lines 15.15 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 5
loc 33
rs 10
c 0
b 0
f 0
wmc 18
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseRequest() 0 5 2
C validate() 5 24 16

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
/**
4
 * Active form input  pasword changer
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Ui\ActiveForm\Input;
13
14
class ChangePassword extends \Ui\ActiveForm\Input {
15
16
    public function parseRequest($request) {
17
        if (!empty($request[$this->colName]['pass'])) {
18
            $this->activeForm->model->{$this->colName} = \App::$cur->users->hashpass($request[$this->colName]['pass']);
19
        }
20
    }
21
22
    public function validate(&$request) {
23
        if (
24
            (!empty($this->colParams['required']) && (empty($request[$this->colName]['pass']) || empty($request[$this->colName]['repeat']))) ||
25
            (!empty($this->colParams['requiredOnNew']) && !$this->activeForm->model->pk() && (empty($request[$this->colName]['pass']) || empty($request[$this->colName]['repeat']))) ||
26
            (!empty($request[$this->colName]['pass']) && empty($request[$this->colName]['repeat'])) ||
27
            (empty($request[$this->colName]['pass']) && !empty($request[$this->colName]['repeat']))
28
        ) {
29
            if (empty($request[$this->colName]['pass'])) {
30
                throw new \Exception('Вы не ввели новый пароль');
31
            }
32
            if (empty($request[$this->colName]['repeat'])) {
33
                throw new \Exception('Вы не ввели подтверждение нового пароля');
34
            }
35
            if ($request[$this->colName]['pass'] != $request[$this->colName]['repeat']) {
36
                throw new \Exception('Введенные пароли не совпадают');
37
            }
38
        }
39
40 View Code Duplication
        if (!empty($this->colParams['validator'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
            $modelName = $this->modelName;
42
            $validator = $modelName::validator($this->colParams['validator']);
43
            $validator($this->activeForm, $request);
44
        }
45
    }
46
}
47