RoleResourceTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fields() 0 29 1
A getModel() 0 3 1
1
<?php
2
3
namespace Insenseanalytics\LaravelNovaPermission;
4
5
use Laravel\Nova\Nova;
0 ignored issues
show
Bug introduced by
The type Laravel\Nova\Nova 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 Laravel\Nova\Fields\ID;
0 ignored issues
show
Bug introduced by
The type Laravel\Nova\Fields\ID 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...
7
use Illuminate\Http\Request;
8
use Laravel\Nova\Fields\Text;
0 ignored issues
show
Bug introduced by
The type Laravel\Nova\Fields\Text 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...
9
use Illuminate\Validation\Rule;
0 ignored issues
show
Bug introduced by
The type Illuminate\Validation\Rule 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...
10
use Laravel\Nova\Fields\Select;
0 ignored issues
show
Bug introduced by
The type Laravel\Nova\Fields\Select 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...
11
use Laravel\Nova\Fields\DateTime;
0 ignored issues
show
Bug introduced by
The type Laravel\Nova\Fields\DateTime 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...
12
use Laravel\Nova\Fields\MorphToMany;
0 ignored issues
show
Bug introduced by
The type Laravel\Nova\Fields\MorphToMany 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
use Laravel\Nova\Fields\BelongsToMany;
0 ignored issues
show
Bug introduced by
The type Laravel\Nova\Fields\BelongsToMany 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...
14
use Spatie\Permission\PermissionRegistrar;
15
16
trait RoleResourceTrait
17
{
18
	public static function getModel()
19
	{
20
		return app(PermissionRegistrar::class)->getRoleClass();
0 ignored issues
show
Bug introduced by
The function app 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

20
		return /** @scrutinizer ignore-call */ app(PermissionRegistrar::class)->getRoleClass();
Loading history...
21
	}
22
23
	/**
24
	 * Get the fields displayed by the resource.
25
	 *
26
	 * @param \Illuminate\Http\Request $request
27
	 *
28
	 * @return array
29
	 */
30
	public function fields(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

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

30
	public function fields(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
	{
32
		$guardOptions = collect(config('auth.guards'))->mapWithKeys(function ($value, $key) {
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

32
		$guardOptions = collect(/** @scrutinizer ignore-call */ config('auth.guards'))->mapWithKeys(function ($value, $key) {
Loading history...
33
			return [$key => $key];
34
		});
35
36
		$userResource = Nova::resourceForModel(getModelForGuard($this->guard_name));
37
38
		$permissionResource = Nova::resourceForModel(app(PermissionRegistrar::class)->getPermissionClass());
0 ignored issues
show
Bug introduced by
The function app 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

38
		$permissionResource = Nova::resourceForModel(/** @scrutinizer ignore-call */ app(PermissionRegistrar::class)->getPermissionClass());
Loading history...
39
40
		return [
41
			ID::make()->sortable(),
42
43
			Text::make(__('laravel-nova-permission::roles.name'), 'name')
0 ignored issues
show
Bug introduced by
The function __ 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

43
			Text::make(/** @scrutinizer ignore-call */ __('laravel-nova-permission::roles.name'), 'name')
Loading history...
44
				->rules(['required', 'string', 'max:255'])
45
				->creationRules('unique:' . config('permission.table_names.roles'))
46
				->updateRules('unique:' . config('permission.table_names.roles') . ',name,{{resourceId}}'),
47
48
			Select::make(__('laravel-nova-permission::roles.guard_name'), 'guard_name')
49
				->options($guardOptions->toArray())
50
				->rules(['required', Rule::in($guardOptions)]),
51
52
			DateTime::make(__('laravel-nova-permission::roles.created_at'), 'created_at')->exceptOnForms(),
53
54
			DateTime::make(__('laravel-nova-permission::roles.updated_at'), 'updated_at')->exceptOnForms(),
55
56
			BelongsToMany::make($permissionResource::label(), 'permissions', $permissionResource)->searchable(),
57
58
			MorphToMany::make($userResource::label(), 'users', $userResource)->searchable(),
59
		];
60
	}
61
}
62