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

AdminQuery   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 36.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
dl 22
loc 60
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A canLogin() 0 6 1
A email() 0 4 1
A username() 0 4 1
A passwordResetToken() 11 11 2
A emailConfirmationToken() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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