Completed
Push — master ( 85aed2...e3f8d4 )
by Charles
04:40
created

ChangeEmailAction::post()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace yrc\api\actions;
4
5
use app\forms\ChangeEmail;
6
use yrc\rest\Action as RestAction;
7
8
use yii\web\HttpException;
9
use Yii;
10
11
/**
12
 * @class ChangeEmailAction
13
 * Handles enabling and disabling of OTP
14
 */
15
class ChangeEmailAction extends RestAction
16
{
17
    /**
18
     * Allows the user to change the email address associated to their account
19
     * @return boolean
20
     */
21
    public static function post($params)
0 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
    {
23
        $model = new ChangeEmail;
24
        
25
        if ($model->load(['ChangeEmail' => Yii::$app->request->post()])) {
26
            // Set the user
27
            $model->setUser(Yii::$app->yrc->userClass::findOne([
28
                'id' => Yii::$app->user->id
29
            ]));
30
31
            if ($model->change()) {
32
                return true;
33
            }
34
35
            throw new HttpException(400, \json_encode($model->getErrors()));
36
        }
37
            
38
        return false;
39
    }
40
}