Completed
Push — master ( 7ceac0...7f8a05 )
by Paras
17s
created

TranslationHandelTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getGuardForModel() 0 6 1
A applyFilters() 0 8 2
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
	 *
23
	 * @return \Illuminate\Database\Eloquent\Builder
24
	 */
25
	protected static function applyFilters(NovaRequest $request, $query, array $filters) {
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
}