Test Failed
Push — master ( abca1b...003db0 )
by Terzi
03:54
created

AllowsNavigation::order()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Terranet\Administrator\Traits\Module;
4
5
use Terranet\Administrator\Architect;
6
use Terranet\Administrator\Contracts\Module\Navigable;
7
8
trait AllowsNavigation
9
{
10
    /**
11
     * Cast to string
12
     * Make module Routable.
13
     * It allows referencing module object while generating routes.
14
     *
15
     * @return mixed
16
     */
17
    public function __toString()
18
    {
19
        return $this->url();
20
    }
21
22
    /**
23
     * The module singular title.
24
     *
25
     * @return mixed
26
     */
27
    public function singular()
28
    {
29
        return str_singular($this->title());
0 ignored issues
show
Deprecated Code introduced by
The function str_singular() has been deprecated: Str::singular() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

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

29
        return /** @scrutinizer ignore-deprecated */ str_singular($this->title());

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...
30
    }
31
32
    /**
33
     * The module title.
34
     *
35
     * @return mixed
36
     */
37
    public function title()
38
    {
39
        return $this->translator()->has($key = $this->translationKey())
0 ignored issues
show
Bug introduced by
The method translator() does not exist on Terranet\Administrator\T...Module\AllowsNavigation. Did you maybe mean translationKey()? ( Ignorable by Annotation )

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

39
        return $this->/** @scrutinizer ignore-call */ translator()->has($key = $this->translationKey())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
            ? 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

40
            ? /** @scrutinizer ignore-call */ trans($key)
Loading history...
41
            : Architect::humanize($this);
42
    }
43
44
    /**
45
     * Navigation container which Resource belongs to.
46
     * Available: sidebar, tools
47
     *
48
     * @return mixed
49
     */
50
    public function navigableIn()
51
    {
52
        return Navigable::MENU_SIDEBAR;
53
    }
54
55
    /**
56
     * Append default params to navigation link.
57
     * Useful for default filters, scopes, etc...
58
     *
59
     * @return array
60
     */
61
    public function navigableParams(): array
62
    {
63
        return [];
64
    }
65
66
    /**
67
     * Add resource to navigation if condition accepts.
68
     *
69
     * @return mixed
70
     */
71
    public function showIf()
72
    {
73
        return ($guard = $this->guard()) && method_exists($guard, 'showIf')
0 ignored issues
show
Bug introduced by
It seems like guard() 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

73
        return ($guard = $this->/** @scrutinizer ignore-call */ guard()) && method_exists($guard, 'showIf')
Loading history...
74
            ? $guard->showIf()
75
            : true;
76
    }
77
78
    /**
79
     * Appends count of items to a navigation.
80
     *
81
     * @return bool
82
     */
83
    public function appendCount()
84
    {
85
        return null;
86
    }
87
88
    /**
89
     * Add resource to navigation as link or header.
90
     *
91
     * @return mixed
92
     */
93
    public function showAs()
94
    {
95
        return Navigable::AS_LINK;
96
    }
97
98
    /**
99
     * Navigation group which module belongs to.
100
     *
101
     * @return string
102
     */
103
    public function group()
104
    {
105
        return trans('administrator::module.groups.resources');
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

105
        return /** @scrutinizer ignore-call */ trans('administrator::module.groups.resources');
Loading history...
106
    }
107
108
    /**
109
     * Resource order number.
110
     *
111
     * @return int
112
     */
113
    public function order()
114
    {
115
        return null;
116
    }
117
118
    /**
119
     * Attributes assigned to <a> element.
120
     *
121
     * @return mixed
122
     */
123 2
    public function linkAttributes()
124
    {
125 2
        return ['icon' => null, 'id' => $this->url()];
126
    }
127
128
    /**
129
     * The module url.
130
     *
131
     * @return mixed
132
     */
133
    public function url()
134
    {
135
        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 6.0. ( Ignorable by Annotation )

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

135
        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...
136
    }
137
138
    public function translationKey()
139
    {
140
        return sprintf('administrator::module.resources.%s', $this->url());
141
    }
142
}
143