GetUserByUsernameOrEmailCriteria::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Yeelight\Repositories\Criteria;
4
5
use Prettus\Repository\Contracts\CriteriaInterface;
6
use Prettus\Repository\Contracts\RepositoryInterface;
7
use Yeelight\Http\Requests\Api\SocialiteAuthRequest;
8
9
/**
10
 * Class GetUserByUsernameOrEmailCriteria
11
 *
12
 * @category Yeelight
13
 *
14
 * @package Yeelight\Repositories\Criteria
15
 *
16
 * @author Sheldon Lee <[email protected]>
17
 *
18
 * @license https://opensource.org/licenses/MIT MIT
19
 *
20
 * @link https://www.yeelight.com
21
 */
22
class GetUserByUsernameOrEmailCriteria implements CriteriaInterface
23
{
24
    public function __construct(SocialiteAuthRequest $request)
25
    {
26
        $this->request = $request;
0 ignored issues
show
Bug Best Practice introduced by
The property request does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
    }
28
29
    public function apply($model, RepositoryInterface $repository)
30
    {
31
        if ($this->request->email) {
32
            $model = $model
33
                ->where('email', '=', $this->request->email)
34
                ->orWhere('email', '=', $this->request->username)
35
                ->orWhere('username', '=', $this->request->username);
36
        } else {
37
            $model = $model
38
                ->where('username', '=', $this->request->username)
39
                ->orWhere('email', '=', $this->request->username);
40
        }
41
42
        return $model;
43
    }
44
}
45