User   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 22 1
A beforeSave() 0 7 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: zjw
5
 * Date: 2017/8/18
6
 * Time: 下午12:54
7
 */
8
9
namespace zacksleo\yii2\backend\tests\models;
10
11
use yii\base\InvalidParamException;
12
use yii\helpers\ArrayHelper;
13
14
class User extends \mdm\admin\models\User
15
{
16
    const STATUS_ACTIVE = 10;
17
    const STATUS_INACTIVE = 0;
18
19
    public function rules()
20
    {
21
        return
22
            [
23
                [['username', 'email', 'password_hash'], 'required', 'on' => 'reset'],
24
                ['username', 'match', 'pattern' => '/^[a-z]\w*$/i', 'on' => 'reset'],
25
                ['password_hash', 'match', 'pattern' => '/\d/', 'message' => '密码至少包含一位数字'],
26
                ['password_hash', 'match', 'pattern' => '/[a-zA-Z]/', 'message' => '密码至少包含一个字母'],
27
28
                ['username', 'filter', 'filter' => 'trim'],
29
                ['username', 'unique'],
30
                ['username', 'string', 'min' => 2, 'max' => 255],
31
32
                ['email', 'filter', 'filter' => 'trim'],
33
                ['email', 'email'],
34
                ['email', 'unique'],
35
36
                ['status', 'default', 'value' => self::STATUS_ACTIVE],
37
                ['status', 'in', 'range' => [self::STATUS_ACTIVE, self::STATUS_INACTIVE]],
38
39
            ];
40
    }
41
42
    public function beforeSave($insert)
43
    {
44
        if (!$this->validate()) {
45
            throw new InvalidParamException($this->getErrors());
0 ignored issues
show
Deprecated Code introduced by
The class yii\base\InvalidParamException has been deprecated with message: since 2.0.14. Use [[InvalidArgumentException]] instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
46
        }
47
        return parent::beforeSave($insert);
48
    }
49
}
50