AuthUserProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 45
ccs 0
cts 13
cp 0
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A retrieveValue() 0 7 2
A retrieveByCredentials() 0 17 3
A searchMethod() 0 3 2
1
<?php
2
3
namespace Terranet\Administrator;
4
5
use Illuminate\Auth\EloquentUserProvider;
0 ignored issues
show
Bug introduced by
The type Illuminate\Auth\EloquentUserProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Str;
7
use Terranet\Administrator\Traits\CallableTrait;
8
9
/**
10
 * Class AuthUserProvider.
11
 */
12
class AuthUserProvider extends EloquentUserProvider
13
{
14
    use CallableTrait;
15
16
    public function retrieveByCredentials(array $credentials)
17
    {
18
        // First we will add each credential element to the query as a where clause.
19
        // Then we can execute the query and, if we found a user, return it in a
20
        // Eloquent User "model" that will be utilized by the Guard instances.
21
        $query = $this->createModel()->newQuery();
22
23
        foreach ($credentials as $key => $value) {
24
            if (!Str::contains($key, 'password')) {
25
                // handle closures
26
                $value = $this->retrieveValue($value);
27
28
                $query = \call_user_func_array([$query, $this->searchMethod($value)], [$key, $value]);
29
            }
30
        }
31
32
        return $query->first();
33
    }
34
35
    /**
36
     * @param $value
37
     *
38
     * @return string
39
     */
40
    protected function searchMethod($value)
41
    {
42
        return \is_array($value) ? 'whereIn' : 'where';
43
    }
44
45
    /**
46
     * @param $value
47
     *
48
     * @return mixed
49
     */
50
    protected function retrieveValue($value)
51
    {
52
        if (\is_callable($value)) {
53
            $value = $this->callback($value);
54
        }
55
56
        return $value;
57
    }
58
}
59