DeleteController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 9
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A actionIndex() 9 17 4

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 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