OracleUserProvider::retrieveByCredentials()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 19
ccs 0
cts 13
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Yajra\Oci8\Auth;
4
5
use Illuminate\Auth\EloquentUserProvider;
6
use Illuminate\Support\Str;
7
8
class OracleUserProvider extends EloquentUserProvider
9
{
10
    /**
11
     * Retrieve a user by the given credentials.
12
     *
13
     * @param  array $credentials
14
     * @return \Illuminate\Contracts\Auth\Authenticatable|null
15
     */
16
    public function retrieveByCredentials(array $credentials)
17
    {
18
        if (empty($credentials)) {
19
            return;
20
        }
21
22
        // First we will add each credential element to the query as a where clause.
23
        // Then we can execute the query and, if we found a user, return it in a
24
        // Eloquent User "model" that will be utilized by the Guard instances.
25
        $query = $this->createModel()->newQuery();
26
27
        foreach ($credentials as $key => $value) {
28
            if (! Str::contains($key, 'password')) {
29
                $query->whereRaw("upper({$key}) = upper(?)", [$value]);
30
            }
31
        }
32
33
        return $query->first();
34
    }
35
}
36