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

ChangeEmailAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A post() 0 19 3
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
}