Passed
Push — master ( e64e78...a7ea07 )
by Paweł
03:04
created

AccountController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

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