Passed
Pull Request — master (#4)
by
unknown
01:44
created

TranslationHandelTrait::getGuardForModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: work
5
 * Date: 2018/12/14
6
 * Time: 16:03
7
 */
8
9
namespace Insenseanalytics\LaravelNovaPermission;
10
11
12
use Laravel\Nova\Http\Requests\NovaRequest;
0 ignored issues
show
Bug introduced by
The type Laravel\Nova\Http\Requests\NovaRequest 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...
13
14
trait TranslationHandelTrait {
15
16
    /**
17
     * Override the applyFilters method to add the guard_name condition when filtering
18
     *
19
     * @param  \Laravel\Nova\Http\Requests\NovaRequest  $request
20
     * @param  \Illuminate\Database\Eloquent\Builder  $query
21
     * @param  array  $filters
22
     * @return \Illuminate\Database\Eloquent\Builder
23
     */
24
    protected static function applyFilters(NovaRequest $request, $query, array $filters)
25
    {
26
        $query = parent::applyFilters($request, $query, $filters);
27
        if($model = head($request->__memoized)){
28
            $guard_name = $model->guard_name ?? self::getGuardForModel(get_class($model));
29
            $query->where('guard_name', $guard_name);
30
        }
31
32
        return $query;
33
    }
34
35
    /**
36
     * @param string model
0 ignored issues
show
Bug introduced by
The type Insenseanalytics\LaravelNovaPermission\model 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...
37
     *
38
     * @return string|null
39
     */
40
    public static function getGuardForModel(string $model) {
41
42
        return collect(config('auth.guards'))
0 ignored issues
show
Bug introduced by
The function config 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

42
        return collect(/** @scrutinizer ignore-call */ config('auth.guards'))
Loading history...
43
            ->map(function ($guard) {
44
                return config("auth.providers.{$guard['provider']}.model");
0 ignored issues
show
Bug introduced by
The function config 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

44
                return /** @scrutinizer ignore-call */ config("auth.providers.{$guard['provider']}.model");
Loading history...
45
            })->search($model);
46
    }
47
}