Completed
Push — master ( 149579...032082 )
by zacksleo
44:40 queued 40:51
created

AdminQuery::passwordResetToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 11
loc 11
ccs 6
cts 7
cp 0.8571
crap 2.0116
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace zacksleo\yii2\backend\models\queries;
3
4
use yii\db\ActiveQuery;
5
use zacksleo\yii2\backend\models\Admin;
6
7
class AdminQuery extends ActiveQuery
8
{
9
    /**
10
     * @return AdminQuery the query with conditions for users that can login applied
11
     */
12 5
    public function canLogin()
13
    {
14 5
        return $this->andWhere([
15 5
            'status' => Admin::STATUS_ACTIVE,
16
        ]);
17
    }
18
19
    /**
20
     * @return UserQuery the query with condition for given email applied
21
     */
22 1
    public function email($email)
23
    {
24 1
        return $this->andWhere(['email' => $email]);
25
    }
26
27
    /**
28
     * @return UserQuery the query with condition for given username applied
29
     */
30 4
    public function username($username)
31
    {
32 4
        return $this->andWhere(['username' => $username]);
33
    }
34
35
    /**
36
     * @param string $token the password reset token
37
     * @return UserQuery the query with conditions for valid password reset token applied
38
     */
39 1 View Code Duplication
    public function passwordResetToken($token)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41 1
        $expire = \Yii::$app->params['user.passwordResetTokenExpire'];
42 1
        $parts = explode('_', $token);
43 1
        $timestamp = (int) end($parts);
44 1
        if ($timestamp + $expire < time()) {
45
            // token expired
46
            return $this->andWhere('FALSE');
47
        }
48 1
        return $this->andWhere(['password_reset_token' => $token]);
49
    }
50
51
    /**
52
     * @param string $token the email confirmation token
53
     * @return UserQuery the query with conditions for valid email confirmation token applied
54
     */
55 View Code Duplication
    public function emailConfirmationToken($token)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $expire = \Yii::$app->params['user.emailConfirmationTokenExpire'];
58
        $parts = explode('_', $token);
59
        $timestamp = (int) end($parts);
60
        if ($timestamp + $expire < time()) {
61
            // token expired
62
            return $this->andWhere('FALSE');
63
        }
64
        return $this->andWhere(['email_confirmation_token' => $token]);
65
    }
66
}
67