ResendForm   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 26.09 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A attributeLabels() 0 6 1
A rules() 0 7 1
A resend() 12 12 3

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
namespace inblank\activeuser\models\forms;
4
5
use inblank\activeuser\traits\CommonTrait;
6
use yii;
7
use yii\base\Model;
8
9
class ResendForm extends Model
10
{
11
    use CommonTrait;
12
13
    /**
14
     * @var string user email for register
15
     */
16
    public $email;
17
18
    /** @inheritdoc */
19
    public function attributeLabels()
20
    {
21
        return [
22
            'email' => Yii::t('activeuser_general', 'Email'),
23
        ];
24
    }
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function rules()
30
    {
31
        return [
32
            ['email', 'required'],
33
            ['email', 'email'],
34
        ];
35
    }
36
37
    /**
38
     * Resend
39
     * @return bool
40
     * @throws yii\base\InvalidConfigException
41
     */
42 View Code Duplication
    public function resend()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
43
    {
44
        if (!$this->validate()) {
45
            return false;
46
        }
47
        /** @var \inblank\activeuser\models\User $user */
48
        $user = Yii::createObject(self::di('User'))->findOne(['email' => $this->email]);
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...
49
        if ($user) {
50
            $user->resend();
51
        }
52
        return true;
53
    }
54
}
55