ConfirmController::actionIndex()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 11
cp 0
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Command;
13
14
use Da\User\Query\UserQuery;
15
use Da\User\Service\UserConfirmationService;
16
use Da\User\Traits\ContainerAwareTrait;
17
use Yii;
18
use yii\base\Module;
19
use yii\console\Controller;
20
use yii\helpers\Console;
21
22
class ConfirmController extends Controller
23
{
24
    use ContainerAwareTrait;
25
26
    protected $userQuery;
27
28
    public function __construct($id, Module $module, UserQuery $userQuery, array $config = [])
29
    {
30
        $this->userQuery = $userQuery;
31
32
        parent::__construct($id, $module, $config);
33
    }
34
35
    /**
36
     * Confirms a a user by setting its field `confirmed_at` to current time.
37
     *
38
     * @param string $usernameOrEmail Username or email of the user
39
     *
40
     * @throws \yii\base\InvalidConfigException
41
     */
42
    public function actionIndex($usernameOrEmail)
43
    {
44
        $user = $this->userQuery->whereUsernameOrEmail($usernameOrEmail)->one();
45
        if ($user === null) {
46
            $this->stdout(Yii::t('usuario', 'User is not found') . "\n", Console::FG_RED);
47
        } elseif ($this->make(UserConfirmationService::class, [$user])->run()) {
48
            $this->stdout(Yii::t('usuario', 'User has been confirmed') . "\n", Console::FG_GREEN);
49
        } else {
50
            $this->stdout(Yii::t('usuario', 'Error occurred while confirming user') . "\n", Console::FG_RED);
51
        }
52
    }
53
}
54