RegisterForm   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 62
c 0
b 0
f 0
rs 10
ccs 18
cts 18
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A attributeLabels() 0 8 1
A rules() 0 15 1
A register() 0 10 2
1
<?php
2
3
namespace inblank\activeuser\models\forms;
4
5
use inblank\activeuser\traits\CommonTrait;
6
use yii;
7
use yii\base\Model;
8
9
class RegisterForm extends Model
10
{
11
    use CommonTrait;
12
13
    /**
14
     * @var string user email for register
15
     */
16
    public $email;
17
    /**
18
     * @var string user name for register
19
     */
20
    public $name;
21
    /**
22
     * @var string user password for register
23
     */
24
    public $password;
25
26
    /** @inheritdoc */
27 4
    public function attributeLabels()
28
    {
29
        return [
30 4
            'email' => Yii::t('activeuser_general', 'Email'),
31 4
            'name' => Yii::t('activeuser_general', 'Name'),
32 4
            'password' => Yii::t('activeuser_general', 'Password'),
33
        ];
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39 4
    public function rules()
40
    {
41
        return [
42 4
            ['email', 'required'],
43
            ['email', 'email'],
44 4
            ['email', 'unique', 'targetClass' => self::di('User'), 'targetAttribute' => 'email'],
45
            ['name', 'required', 'when' => function () {
46 4
                return $this->getModule()->isFieldForRegister('name');
47 4
            }],
48 4
            ['password', 'required', 'when' => function () {
49 4
                return $this->getModule()->isFieldForRegister('password');
50 4
            }],
51
            ['password', 'string', 'length' => [6, 20], 'skipOnEmpty' => true],
52
        ];
53
    }
54
55
    /**
56
     * Registration
57
     * @return bool
58
     * @throws yii\base\InvalidConfigException
59
     */
60 4
    public function register()
61
    {
62 4
        if (!$this->validate()) {
63 4
            return false;
64
        }
65
        /** @var \inblank\activeuser\models\User $user */
66 4
        $user = Yii::createObject(self::di('User'));
0 ignored issues
show
Documentation introduced by
self::di('User') is of type *, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67 4
        $user->setAttributes($this->getAttributes());
68 4
        return $user->register();
69
    }
70
}
71