Passed
Push — master ( c21c1f...04db2a )
by Wilmer
01:51
created

ResetPasswordForm::resetPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace app\basic\forms;
4
5
use app\basic\models\UserModels;
6
use yii\base\Application;
7
use yii\base\Model;
8
9
/**
10
 * ResetPasswordForm is the model behind the reset password form Web Application Basic.
11
 **/
12
class ResetPasswordForm extends Model
13
{
14
	public $password;
15
16
    private $_user;
17
18
    protected $app;
19
20
    /**
21
     * __construct
22
     *
23
     * @param Application $app, string $token
24
     **/
25
    public function __construct(Application $app, string $token)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

25
    public function __construct(/** @scrutinizer ignore-unused */ Application $app, string $token)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        $this->_user = UserModels::findByPasswordResetToken($token);
28
    }
29
30
	/**
31
     * rules
32
     *
33
	 * @return array the validation rules.
34
	 **/
35
	public function rules()
36
	{
37
		return [
38
			['password', 'required'],
39
			['password', 'string', 'min' => 6],
40
		];
41
	}
42
43
	/**
44
	 * atributeLabels
45
	 * Translate Atribute Labels.
46
     *
47
	 * @return array customized attribute labels.
48
	 **/
49
	public function attributeLabels()
50
	{
51
		return [
52
			'password' => $this->app->t('basic', 'Password'),
53
		];
54
	}
55
56
	/**
57
     * resetPassword
58
	 * Resets password.
59
	 *
60
	 * @return bool if password was reset.
61
	 **/
62
	public function resetPassword()
63
	{
64
		$this->_user->setPassword($this->password);
65
		$this->_user->removePasswordResetToken();
66
67
		return $this->_user->save(false);
68
	}
69
}
70