UpdatePasswordController::actionIndex()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 9
Ratio 56.25 %

Importance

Changes 0
Metric Value
dl 9
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace yii2mod\user\commands;
4
5
use Yii;
6
use yii\console\Controller;
7
use yii\helpers\Console;
8
use yii2mod\user\models\UserModel;
9
10
/**
11
 * Class UpdatePasswordController
12
 *
13
 * @package yii2mod\user\commands
14
 */
15
class UpdatePasswordController extends Controller
16
{
17
    /**
18
     * Updates user's password to given.
19
     *
20
     * @param $email
21
     * @param $password
22
     *
23
     * @return int
24
     */
25
    public function actionIndex($email, $password)
26
    {
27
        $user = UserModel::findByEmail($email);
28
29 View Code Duplication
        if ($user === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
30
            $this->stdout(Yii::t('yii2mod.user', 'User is not found.') . "\n", Console::FG_RED);
31
        } else {
32
            if ($user->resetPassword($password)) {
33
                $this->stdout(Yii::t('yii2mod.user', 'Password has been changed.') . "\n", Console::FG_GREEN);
34
            } else {
35
                $this->stdout(Yii::t('yii2mod.user', 'Error occurred while changing password.') . "\n", Console::FG_RED);
36
            }
37
        }
38
39
        return self::EXIT_CODE_NORMAL;
0 ignored issues
show
Deprecated Code introduced by
The constant yii\console\Controller::EXIT_CODE_NORMAL has been deprecated with message: since 2.0.13. Use [[ExitCode::OK]] instead.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
40
    }
41
}
42