ResetPasswordForm   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 4
A rules() 0 7 1
A resetPassword() 0 4 1
1
<?php
2
namespace zacksleo\yii2\backend\models\forms;
3
4
use yii\base\Model;
5
use yii\base\InvalidParamException;
6
use zacksleo\yii2\backend\models\Admin;
7
8
/**
9
 * Password reset form
10
 */
11
class ResetPasswordForm extends Model
12
{
13
    public $password;
14
15
    /**
16
     * @var \zacksleo\yii2\backend\models\Admin
17
     */
18
    private $_user;
19
20
21
    /**
22
     * Creates a form model given a token.
23
     *
24
     * @param string $token
25
     * @param array $config name-value pairs that will be used to initialize the object properties
26
     * @throws \yii\base\InvalidParamException if token is empty or not valid
27
     */
28 1
    public function __construct($token, $config = [])
29
    {
30 1
        if (empty($token) || !is_string($token)) {
31 1
            throw new InvalidParamException('Password reset token cannot be blank.');
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...
32
        }
33 1
        $this->_user = Admin::find()->canLogin()->passwordResetToken($token)->one();
0 ignored issues
show
Documentation Bug introduced by
It seems like \zacksleo\yii2\backend\m...setToken($token)->one() can also be of type object<yii\db\ActiveRecord> or array. However, the property $_user is declared as type object<zacksleo\yii2\backend\models\Admin>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
34 1
        if (!$this->_user) {
35 1
            throw new InvalidParamException('Wrong password reset token.');
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...
36
        }
37 1
        parent::__construct($config);
38 1
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43 1
    public function rules()
44
    {
45
        return [
46 1
            ['password', 'required'],
47
            ['password', 'string', 'min' => 6],
48
        ];
49
    }
50
51
    /**
52
     * Resets password.
53
     *
54
     * @return bool if password was reset.
55
     */
56 1
    public function resetPassword()
57
    {
58 1
        return $this->_user->resetPassword($this->password);
59
    }
60
}
61