Completed
Push — master ( 9c0f6d...e28c7c )
by Alexey
37:38
created

SignupAction::trigger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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
        ]);
47
    }
48
49
//    public function trigger($name, Event $event = null)
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
//    {
51
//        Yii::$app->trigger(sprintf('yiicod.auth.actions.webUser.SignupAction.%s', $name), $event);
52
53
//        return parent::trigger($name, $event);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
//    }
55
}
56