ActionSkeleton   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 75
ccs 0
cts 11
cp 0
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 8 1
A confirmationMessage() 0 3 1
A hideFromIndex() 0 3 1
A attributes() 0 8 2
A route() 0 6 2
A hideFromView() 0 3 1
1
<?php
2
3
namespace Terranet\Administrator\Traits\Actions;
4
5
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Eloquent\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...
6
use Illuminate\Foundation\Auth\User;
0 ignored issues
show
Bug introduced by
The type Illuminate\Foundation\Auth\User 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\Support\Str;
8
use Terranet\Administrator\Contracts\Module;
9
10
trait ActionSkeleton
11
{
12
    /**
13
     * Check if specified user is authorized to execute this action.
14
     *
15
     * @param  User  $viewer
16
     * @param  Model  $model
17
     * @return bool
18
     */
19
    public function authorize(User $viewer, Model $model = null)
0 ignored issues
show
Unused Code introduced by
The parameter $viewer 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

19
    public function authorize(/** @scrutinizer ignore-unused */ User $viewer, Model $model = null)

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...
20
    {
21
        /** @var Module $resource */
22
        $resource = app('scaffold.module');
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

22
        $resource = /** @scrutinizer ignore-call */ app('scaffold.module');
Loading history...
23
24
        return $resource->actions()->authorize(
25
            Str::snake(class_basename($this)),
26
            $model
27
        );
28
    }
29
30
    /**
31
     * @param  Model  $model
32
     * @return string
33
     */
34
    public function route(Model $model = null)
35
    {
36
        return route('scaffold.action', [
0 ignored issues
show
Bug introduced by
The function route 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

36
        return /** @scrutinizer ignore-call */ route('scaffold.action', [
Loading history...
37
            'module' => app('scaffold.module'),
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

37
            'module' => /** @scrutinizer ignore-call */ app('scaffold.module'),
Loading history...
38
            'id' => $model ? $model->getKey() : null,
39
            'action' => $this->action($model),
0 ignored issues
show
Bug introduced by
It seems like action() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

39
            'action' => $this->/** @scrutinizer ignore-call */ action($model),
Loading history...
40
        ]);
41
    }
42
43
    /**
44
     * Confirmation message, if required.
45
     *
46
     * @return mixed null|string
47
     */
48
    protected function confirmationMessage(): ?string
49
    {
50
        return null;
51
    }
52
53
    /**
54
     * Hide an action from index page.
55
     *
56
     * @return bool
57
     */
58
    public function hideFromIndex(): bool
59
    {
60
        return false;
61
    }
62
63
    /**
64
     * Hide an action from view page.
65
     *
66
     * @return bool
67
     */
68
    public function hideFromView(): bool
69
    {
70
        return false;
71
    }
72
73
    /**
74
     * @param  Model  $model
75
     * @return string
76
     */
77
    protected function attributes(Model $model = null)
0 ignored issues
show
Unused Code introduced by
The parameter $model 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

77
    protected function attributes(/** @scrutinizer ignore-unused */ Model $model = null)

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...
78
    {
79
        $attributes = [];
80
        if ($msg = $this->confirmationMessage()) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $msg is correct as $this->confirmationMessage() targeting Terranet\Administrator\T...::confirmationMessage() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
81
            $attributes["onclick"] = "return window.confirm('{$msg}')";
82
        }
83
84
        return \admin\helpers\html_attributes($attributes);
85
    }
86
}
87