Completed
Push — master ( 8237b9...71710d )
by Charles
02:19
created

RefreshAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A post() 0 20 3
1
<?php
2
3
namespace yrc\api\actions;
4
5
use yrc\api\actions\AuthenticationAction;
6
use app\models\Token;
7
use yrc\rest\Action as RestAction;
8
9
use Yii;
10
11
/**
12
 * @class RefreshAction
13
 * Handles token refresh
14
 */
15
class RefreshAction extends RestAction
16
{
17
    /**
18
     * Refreshes the user's token
19
     * @return bool
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
        // Get the token
24
        $token = AuthenticationAction::getAccessTokenFromHeader();
25
        
26
        $refreshToken = Yii::$app->request->post('refresh_token', false);
27
28
        if ($refreshToken !== $token->refreshToken) {
29
            return false;
30
        }
31
32
        // If we can delete the token, send a newly generated token out
33
        if ($token->delete()) {
34
            $tokens = Token::generate(Yii::$app->user->id);
0 ignored issues
show
Unused Code introduced by
$tokens is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
35
            return $data;
0 ignored issues
show
Bug introduced by
The variable $data does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
        }
37
38
        // Return false for any other reasons
39
        return false;
40
    }
41
}