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

Skeleton   A

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
7
trait Skeleton
8
{
9
    /**
10
     * @return string
11
     */
12
    public function type(): string
13
    {
14
        return 'primary';
15
    }
16
17
    /**
18
     * Render action button.
19
     *
20
     * @param  Eloquent  $entity
21
     * @return string
22
     */
23
    public function render(Eloquent $entity = null)
24
    {
25
        $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

25
        $action = /** @scrutinizer ignore-call */ app('scaffold.module')->url().'-'.$this->action($entity);
Loading history...
26
        $icon = ($i = $this->icon($entity)) ? "<i class=\"fa {$i}\"></i>" : '';
27
28
        return
29
            <<<OUTPUT
30
<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 $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

30
<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 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

30
<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 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

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

44
        $action = /** @scrutinizer ignore-call */ app('scaffold.module')->url().'-'.$this->action($entity);
Loading history...
45
        $icon = ($i = $this->icon($entity)) ? "<i class=\"fa {$i}\"></i>" : '';
46
47
        return
48
            <<<OUTPUT
49
<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

49
<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...
50
    {$icon}<span>{$this->name($entity)}</span>
51
</a>
52
OUTPUT;
53
    }
54
55
    /**
56
     * @param  Eloquent  $entity
57
     * @return string
58
     */
59
    protected 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

59
    protected 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...
60
    {
61
        return 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

61
        return /** @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...
62
    }
63
64
    /**
65
     * Action name.
66
     *
67
     * @param  Eloquent  $entity
68
     * @return string
69
     */
70
    protected 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

70
    protected 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...
71
    {
72
        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

72
        return /** @scrutinizer ignore-call */ app('translator')->has($key = $this->translationKey())
Loading history...
73
            ? 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

73
            ? /** @scrutinizer ignore-call */ trans($key)
Loading history...
74
            : title_case(str_replace('_', ' ', 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

74
            : title_case(str_replace('_', ' ', /** @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...
Deprecated Code introduced by
The function title_case() has been deprecated: Str::title() 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

74
            : /** @scrutinizer ignore-deprecated */ title_case(str_replace('_', ' ', 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...
75
    }
76
77
    /**
78
     * @param  Eloquent  $entity
79
     * @return string
80
     */
81
    protected function icon(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

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

91
        $key = sprintf('administrator::actions.%s.%s', /** @scrutinizer ignore-call */ app('scaffold.module')->url(), snake_case(class_basename($this)));
Loading history...
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

91
        $key = sprintf('administrator::actions.%s.%s', app('scaffold.module')->url(), /** @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...
92
93
        if (!app('translator')->has($key)) {
94
            $key = sprintf('administrator::actions.global.%s', 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

94
            $key = sprintf('administrator::actions.global.%s', /** @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...
95
        }
96
97
        return $key;
98
    }
99
100
    /**
101
     * @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...
102
     * @return string
103
     */
104
    protected function entityKey($entity = null): string
105
    {
106
        return $entity ? $entity->getKey() : 'empty';
0 ignored issues
show
introduced by
$entity is of type null, thus it always evaluated to false.
Loading history...
107
    }
108
}
109