Completed
Push — master ( 831b77...b56796 )
by Antonio
02:41
created

UserQuery   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 54
ccs 10
cts 12
cp 0.8333
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A whereUsernameOrEmail() 0 6 2
A whereEmail() 0 4 1
A whereUsername() 0 4 1
A whereId() 0 4 1
A whereNotId() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Query;
13
14
use yii\db\ActiveQuery;
15
16
class UserQuery extends ActiveQuery
17
{
18
    /**
19
     * @param $usernameOrEmail
20
     *
21
     * @return $this
22
     */
23 5
    public function whereUsernameOrEmail($usernameOrEmail)
24
    {
25 5
        return filter_var($usernameOrEmail, FILTER_VALIDATE_EMAIL)
26 3
            ? $this->whereEmail($usernameOrEmail)
27 5
            : $this->whereUsername($usernameOrEmail);
28
    }
29
30
    /**
31
     * @param $email
32
     *
33
     * @return $this
34
     */
35 5
    public function whereEmail($email)
36
    {
37 5
        return $this->andWhere(['email' => $email]);
38
    }
39
40
    /**
41
     * @param $username
42
     *
43
     * @return $this
44
     */
45 3
    public function whereUsername($username)
46
    {
47 3
        return $this->andWhere(['username' => $username]);
48
    }
49
50
    /**
51
     * @param $id
52
     *
53
     * @return $this
54
     */
55 1
    public function whereId($id)
56
    {
57 1
        return $this->andWhere(['id' => $id]);
58
    }
59
60
    /**
61
     * @param $id
62
     *
63
     * @return $this
64
     */
65
    public function whereNotId($id)
66
    {
67
        return $this->andWhere(['<>', 'id', $id]);
68
    }
69
}
70