SignupAction   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 40
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 24 3
1
<?php
2
3
namespace yiicod\auth\actions\webUser;
4
5
use Yii;
6
use yii\base\Action;
7
use yii\base\Event;
8
use yiicod\auth\events\SignupEvent;
9
10
class SignupAction extends Action
11
{
12
    const EVENT_BEFORE_SIGNUP = 'beforeSignup';
13
    const EVENT_AFTER_SIGNUP = 'afterSignup';
14
    const EVENT_ERROR_SIGNUP = 'errorSignup';
15
16
    public $view = '@yiicod/yii2-auth/views/webUser/signup';
17
18
    /**
19
     * Model scenario
20
     *
21
     * @var
22
     */
23
    public $scenario;
24
25
    public function run()
26
    {
27
        $signupFormClass = Yii::$app->get('auth')->modelMap['signupForm']['class'];
28
        $userClass = Yii::$app->get('auth')->modelMap['user']['class'];
29
        $model = new $signupFormClass($this->scenario);
30
        $user = new $userClass($this->scenario);
31
32
        $isLoad = $model->load(Yii::$app->request->post());
33
34
        Event::trigger(self::class, static::EVENT_BEFORE_SIGNUP, new SignupEvent($this, $user, $model, ['sender' => $this]));
35
36
        if ($isLoad) {
37
            if ($user = $model->signup($user)) {
38
                Event::trigger(self::class, static::EVENT_AFTER_SIGNUP, new SignupEvent($this, $user, $model, ['sender' => $this]));
39
            } else {
40
                Event::trigger(self::class, static::EVENT_ERROR_SIGNUP, new SignupEvent($this, $user, $model, ['sender' => $this]));
41
            }
42
        }
43
44
        return $this->controller->render($this->view, [
45
            'model' => $model,
46
            'user' => $user,
47
        ]);
48
    }
49
}
50