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

ChangePassword::validate()   C

Complexity

Conditions 16
Paths 7

Size

Total Lines 24
Code Lines 16

Duplication

Lines 5
Ratio 20.83 %

Importance

Changes 0
Metric Value
cc 16
eloc 16
nc 7
nop 1
dl 5
loc 24
rs 5.0654
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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