Test Failed
Push — master ( 470d4b...33c92c )
by Terzi
04:31
created

src/AuthUserProvider.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Terranet\Administrator;
4
5
use Illuminate\Auth\EloquentUserProvider;
6
use Terranet\Administrator\Traits\CallableTrait;
7
8
/**
9
 * Class AuthUserProvider.
10
 */
11
class AuthUserProvider extends EloquentUserProvider
12
{
13
    use CallableTrait;
14
15
    public function retrieveByCredentials(array $credentials)
16
    {
17
        // First we will add each credential element to the query as a where clause.
18
        // Then we can execute the query and, if we found a user, return it in a
19
        // Eloquent User "model" that will be utilized by the Guard instances.
20
        $query = $this->createModel()->newQuery();
21
22
        foreach ($credentials as $key => $value) {
23
            if (!str_contains($key, 'password')) {
0 ignored issues
show
The function str_contains was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            if (!/** @scrutinizer ignore-call */ str_contains($key, 'password')) {
Loading history...
24
                // handle closures
25
                $value = $this->retrieveValue($value);
26
27
                $query = \call_user_func_array([$query, $this->searchMethod($value)], [$key, $value]);
28
            }
29
        }
30
31
        return $query->first();
32
    }
33
34
    /**
35
     * @param $value
36
     *
37
     * @return string
38
     */
39
    protected function searchMethod($value)
40
    {
41
        return \is_array($value) ? 'whereIn' : 'where';
42
    }
43
44
    /**
45
     * @param $value
46
     *
47
     * @return mixed
48
     */
49
    protected function retrieveValue($value)
50
    {
51
        if (\is_callable($value)) {
52
            $value = $this->callback($value);
53
        }
54
55
        return $value;
56
    }
57
}
58