Passed
Push — master ( 2c5051...34ca9b )
by Paweł
02:47
created

AccountController::actionUpdateUsername()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 4
nop 1
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created for IG Monitoring.
4
 * User: jakim <[email protected]>
5
 * Date: 13.01.2018
6
 */
7
8
namespace app\commands;
9
10
11
use app\models\Account;
12
use app\models\Tag;
13
use yii\console\Controller;
14
use yii\console\ExitCode;
15
use yii\helpers\Console;
16
use yii\helpers\StringHelper;
17
18
class AccountController extends Controller
19
{
20
    /**
21
     * Update account usernames.
22
     * format: from1,to1;from2,to2;from3,to3
23
     */
24
    public function actionUpdateUsername($usernames)
25
    {
26
        $rows = StringHelper::explode($usernames, ';', true, true);
27
        foreach ($rows as $row) {
28
            $username = StringHelper::explode($row, ',', true, true);
29
            $account = Account::findOne(['username' => $username['0']]);
30
            if ($account) {
31
                $account->username = $username['1'];
32
                if (!$account->update()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $account->update() of type integer|false is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
33
                    echo Console::errorSummary($account);
34
35
                    return ExitCode::DATAERR;
36
                }
37
38
            }
39
        }
40
    }
41
}