Test Failed
Push — master ( 317503...2a406f )
by Terzi
03:56
created

ActionSkeleton::confirmationMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
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 Terranet\Administrator\Contracts\Module;
8
9
trait ActionSkeleton
10
{
11
    /**
12
     * Check if specified user is authorized to execute this action.
13
     *
14
     * @param  User  $viewer
15
     * @param  Model  $model
16
     * @return bool
17
     */
18
    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

18
    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...
19
    {
20
        /** @var Module $resource */
21
        $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

21
        $resource = /** @scrutinizer ignore-call */ app('scaffold.module');
Loading history...
22
23
        return $resource->actionsManager()->authorize(
24
            snake_case(class_basename($this)),
0 ignored issues
show
Deprecated Code introduced by
The function snake_case() has been deprecated: Str::snake() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

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

24
            /** @scrutinizer ignore-deprecated */ snake_case(class_basename($this)),

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
25
            $model
26
        );
27
    }
28
29
    /**
30
     * @param  Model  $model
31
     * @return string
32
     */
33
    protected function route(Model $model = null)
34
    {
35
        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

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

36
            'module' => /** @scrutinizer ignore-call */ app('scaffold.module'),
Loading history...
37
            'id' => $model ? $model->getKey() : null,
38
            '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

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

76
    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...
77
    {
78
        $attributes = [];
79
        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...
80
            $attributes["onclick"] = "return window.confirm('{$msg}')";
81
        }
82
83
        return \admin\helpers\html_attributes($attributes);
84
    }
85
}
86