ValidateController::actionIndex()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 13
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace  andmemasin\emailsvalidator\commands;
4
5
use andmemasin\emailsvalidator\models\EmailAddress;
6
use yii\console\Controller;
7
use yii\console\ExitCode;
8
use yii\helpers\Console;
9
10
class ValidateController extends Controller
11
{
12
13
    public function actionIndex($email)
14
    {
15
        $model = new EmailAddress(['address' => $email]);
16
        $model->address = $email;
17
        $model->validate();
18
19
        if ($model->isValid) {
20
            \Yii::$app->controller->stdout("Address {$email} is valid" . PHP_EOL, Console::FG_GREEN, Console::BOLD);
21
            return ExitCode::OK;
22
        }
23
24
        \Yii::$app->controller->stdout("Address {$email} is not valid!" . PHP_EOL, Console::FG_RED, Console::BOLD);
25
        return ExitCode::UNSPECIFIED_ERROR;
26
27
    }
28
}
29