AllowsNavigation::group()   A
last analyzed

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
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Terranet\Administrator\Traits\Module;
4
5
use Illuminate\Support\Str;
6
use Terranet\Administrator\Architect;
7
use Terranet\Administrator\Contracts\Module\Navigable;
8
9
trait AllowsNavigation
10
{
11
    /**
12
     * Cast to string
13
     * Make module Routable.
14
     * It allows referencing module object while generating routes.
15
     *
16
     * @return mixed
17
     */
18
    public function __toString()
19
    {
20
        return $this->url();
21
    }
22
23
    /**
24
     * The module singular title.
25
     *
26
     * @return mixed
27
     */
28
    public function singular()
29
    {
30
        return Str::singular($this->title());
31
    }
32
33
    /**
34
     * The module title.
35
     *
36
     * @return string
37
     */
38
    public function title(): string
39
    {
40
        return trans()->has($key = $this->translationKey())
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
        return /** @scrutinizer ignore-call */ trans()->has($key = $this->translationKey())
Loading history...
41
            ? trans($key)
42
            : Architect::humanize($this);
43
    }
44
45
    /**
46
     * Navigation container which Resource belongs to.
47
     * Available: sidebar, tools
48
     *
49
     * @return mixed
50
     */
51
    public function navigableIn()
52
    {
53
        return Navigable::MENU_SIDEBAR;
54
    }
55
56
    /**
57
     * Append default params to navigation link.
58
     * Useful for default filters, scopes, etc...
59
     *
60
     * @return array
61
     */
62
    public function navigableParams(): array
63
    {
64
        return [];
65
    }
66
67
    /**
68
     * Add resource to navigation if condition accepts.
69
     *
70
     * @return mixed
71
     */
72
    public function showIf()
73
    {
74
        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

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

106
        return /** @scrutinizer ignore-call */ trans('administrator::module.groups.resources');
Loading history...
107
    }
108
109
    /**
110
     * Resource order number.
111
     *
112
     * @return int
113
     */
114
    public function order()
115
    {
116
        return null;
117
    }
118
119
    /**
120
     * Attributes assigned to <a> element.
121
     *
122
     * @return mixed
123 2
     */
124
    public function linkAttributes()
125 2
    {
126
        return ['icon' => null, 'id' => $this->url()];
127
    }
128
129
    /**
130
     * The module url.
131
     *
132
     * @return string
133
     */
134
    public function url(): string
135
    {
136
        return Str::snake(class_basename($this));
137
    }
138
139
    public function translationKey()
140
    {
141
        return sprintf('administrator::module.resources.%s', $this->url());
142
    }
143
}
144