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

ChangePassword::parseRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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