Passed
Push — master ( 34ca9b...301366 )
by Paweł
02:37
created

AccountController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B actionUpdateName() 0 20 7
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: username1_from,username1_to1,name1;username2_from,username2_to,name2;username3_from,username3_to,name3
23
     */
24
    public function actionUpdateName($names)
25
    {
26
        $rows = StringHelper::explode($names, ';', true, true);
27
        foreach ($rows as $row) {
28
            $username = StringHelper::explode($row);
29
            if (count($username) != 3) {
30
                $this->stdout("Wrong format!\n", Console::BG_RED);
31
            }
32
            $account = Account::findOne(['username' => $username['0']]);
33
            if ($account) {
34
                if ($username['1']) {
35
                    $account->username = $username['1'];
36
                }
37
                if ($username['2']) {
38
                    $account->name = $username['2'];
39
                }
40
                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...
41
                    echo Console::errorSummary($account);
42
43
                    return ExitCode::DATAERR;
44
                }
45
46
            }
47
        }
48
    }
49
}