DeleteController::actionIndex()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17

Duplication

Lines 9
Ratio 52.94 %

Importance

Changes 0
Metric Value
dl 9
loc 17
rs 9.7
c 0
b 0
f 0
cc 4
nc 4
nop 1
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 DeleteController
12
 *
13
 * @package yii2mod\user\commands
14
 */
15
class DeleteController extends Controller
16
{
17
    /**
18
     * Deletes a user.
19
     *
20
     * @param string $email user email
21
     *
22
     * @return int
23
     */
24
    public function actionIndex($email)
25
    {
26
        if ($this->confirm(Yii::t('yii2mod.user', 'Are you sure you want to delete this user?'))) {
27
            $user = UserModel::findByEmail($email);
28 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...
29
                $this->stdout(Yii::t('yii2mod.user', 'User is not found.') . "\n", Console::FG_RED);
30
            } else {
31
                if ($user->delete()) {
32
                    $this->stdout(Yii::t('yii2mod.user', 'User has been deleted.') . "\n", Console::FG_GREEN);
33
                } else {
34
                    $this->stdout(Yii::t('yii2mod.user', 'Error occurred while deleting user.') . "\n", Console::FG_RED);
35
                }
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