Skeleton   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 1 Features 1
Metric Value
eloc 26
c 4
b 1
f 1
dl 0
loc 100
ccs 0
cts 20
cp 0
rs 10
wmc 13

8 Methods

Rating   Name   Duplication   Size   Complexity  
A renderBtn() 0 9 2
A name() 0 5 2
A translationKey() 0 9 2
A action() 0 3 1
A render() 0 9 2
A type() 0 3 1
A entityKey() 0 3 2
A icon() 0 3 1
1
<?php
2
3
namespace Terranet\Administrator\Traits\Actions;
4
5
use Illuminate\Database\Eloquent\Model as Eloquent;
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\Support\Str;
7
8
trait Skeleton
9
{
10
    /**
11
     * @return string
12
     */
13
    protected function type(): string
14
    {
15
        return 'primary';
16
    }
17
18
    /**
19
     * Render action button.
20
     *
21
     * @param  Eloquent  $entity
22
     * @return string
23
     */
24
    public function render(Eloquent $entity = null)
25
    {
26
        $action = app('scaffold.module')->url().'-'.$this->action($entity);
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

26
        $action = /** @scrutinizer ignore-call */ app('scaffold.module')->url().'-'.$this->action($entity);
Loading history...
27
        $icon = ($i = $this->icon($entity)) ? "<i class=\"fa {$i}\"></i>" : '';
28
29
        return
30
            <<<OUTPUT
31
<a data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey($entity)}" href="{$this->route($entity)}" {$this->attributes($entity)}>
0 ignored issues
show
Bug introduced by
It seems like route() 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

31
<a data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey($entity)}" href="{$this->/** @scrutinizer ignore-call */ route($entity)}" {$this->attributes($entity)}>
Loading history...
Bug introduced by
It seems like $entity can also be of type Illuminate\Database\Eloquent\Model; however, parameter $entity of Terranet\Administrator\T...s\Skeleton::entityKey() does only seem to accept null, maybe add an additional type check? ( Ignorable by Annotation )

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

31
<a data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey(/** @scrutinizer ignore-type */ $entity)}" href="{$this->route($entity)}" {$this->attributes($entity)}>
Loading history...
Bug introduced by
It seems like attributes() 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

31
<a data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey($entity)}" href="{$this->route($entity)}" {$this->/** @scrutinizer ignore-call */ attributes($entity)}>
Loading history...
32
    {$icon}<span>{$this->name($entity)}</span>
33
</a>
34
OUTPUT;
35
    }
36
37
    /**
38
     * Render action button.
39
     *
40
     * @param  Eloquent  $entity
41
     * @return string
42
     */
43
    public function renderBtn(Eloquent $entity = null)
44
    {
45
        $action = app('scaffold.module')->url().'-'.$this->action($entity);
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

45
        $action = /** @scrutinizer ignore-call */ app('scaffold.module')->url().'-'.$this->action($entity);
Loading history...
46
        $icon = ($i = $this->icon($entity)) ? "<i class=\"fa {$i}\"></i>" : '';
47
48
        return
49
            <<<OUTPUT
50
<a class="btn btn-{$this->type()}" data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey($entity)}" href="{$this->route($entity)}" {$this->attributes($entity)}>
0 ignored issues
show
Bug introduced by
It seems like $entity can also be of type Illuminate\Database\Eloquent\Model; however, parameter $entity of Terranet\Administrator\T...s\Skeleton::entityKey() does only seem to accept null, maybe add an additional type check? ( Ignorable by Annotation )

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

50
<a class="btn btn-{$this->type()}" data-scaffold-action="{$action}" data-scaffold-key="{$this->entityKey(/** @scrutinizer ignore-type */ $entity)}" href="{$this->route($entity)}" {$this->attributes($entity)}>
Loading history...
51
    {$icon}<span>{$this->name($entity)}</span>
52
</a>
53
OUTPUT;
54
    }
55
56
    /**
57
     * @param  Eloquent  $entity
58
     * @return string
59
     */
60
    public function action(Eloquent $entity = null)
0 ignored issues
show
Unused Code introduced by
The parameter $entity 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

60
    public function action(/** @scrutinizer ignore-unused */ Eloquent $entity = 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...
61
    {
62
        return Str::snake(class_basename($this));
63
    }
64
65
    /**
66
     * Action name.
67
     *
68
     * @param  Eloquent  $entity
69
     * @return string
70
     */
71
    public function name(Eloquent $entity = null)
0 ignored issues
show
Unused Code introduced by
The parameter $entity 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

71
    public function name(/** @scrutinizer ignore-unused */ Eloquent $entity = 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...
72
    {
73
        return app('translator')->has($key = $this->translationKey())
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

73
        return /** @scrutinizer ignore-call */ app('translator')->has($key = $this->translationKey())
Loading history...
74
            ? trans($key)
0 ignored issues
show
Bug introduced by
The function trans 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

74
            ? /** @scrutinizer ignore-call */ trans($key)
Loading history...
75
            : Str::title(str_replace('_', ' ', Str::snake(class_basename($this))));
76
    }
77
78
    /**
79
     * @param  Eloquent  $entity
80
     * @return string
81
     */
82
    public function icon(Eloquent $entity = null): string
0 ignored issues
show
Unused Code introduced by
The parameter $entity 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

82
    public function icon(/** @scrutinizer ignore-unused */ Eloquent $entity = null): string

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...
83
    {
84
        return 'fa-circle-thin';
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    protected function translationKey(): string
91
    {
92
        $key = sprintf('administrator::actions.%s.%s', app('scaffold.module')->url(), Str::snake(class_basename($this)));
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

92
        $key = sprintf('administrator::actions.%s.%s', /** @scrutinizer ignore-call */ app('scaffold.module')->url(), Str::snake(class_basename($this)));
Loading history...
93
94
        if (!app('translator')->has($key)) {
95
            $key = sprintf('administrator::actions.global.%s', Str::snake(class_basename($this)));
96
        }
97
98
        return $key;
99
    }
100
101
    /**
102
     * @param  null  $entity
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $entity is correct as it would always require null to be passed?
Loading history...
103
     * @return string
104
     */
105
    protected function entityKey($entity = null): string
106
    {
107
        return $entity ? $entity->getKey() : 'empty';
0 ignored issues
show
introduced by
$entity is of type null, thus it always evaluated to false.
Loading history...
108
    }
109
}
110