Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — show-operation-with-tabs ( df5564...33ac75 )
by
unknown
13:52
created

Tabs::getTabItems()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 2
nop 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Library\CrudPanel\Traits;
4
5
trait Tabs
6
{
7
    public function enableTabs()
8
    {
9
        $this->setOperationSetting('tabsEnabled', true);
0 ignored issues
show
Bug introduced by
It seems like setOperationSetting() 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

9
        $this->/** @scrutinizer ignore-call */ 
10
               setOperationSetting('tabsEnabled', true);
Loading history...
10
        $this->setOperationSetting('tabsType', config('backpack.crud.operations.'.$this->getCurrentOperation().'.tabsType', 'horizontal'));
0 ignored issues
show
Bug introduced by
It seems like getCurrentOperation() 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

10
        $this->setOperationSetting('tabsType', config('backpack.crud.operations.'.$this->/** @scrutinizer ignore-call */ getCurrentOperation().'.tabsType', 'horizontal'));
Loading history...
11
12
        return $this->tabsEnabled();
13
    }
14
15
    public function disableTabs()
16
    {
17
        $this->setOperationSetting('tabsEnabled', false);
18
19
        return $this->tabsEnabled();
20
    }
21
22
    /**
23
     * @return bool
24
     */
25
    public function tabsEnabled()
26
    {
27
        return $this->getOperationSetting('tabsEnabled');
0 ignored issues
show
Bug introduced by
It seems like getOperationSetting() 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

27
        return $this->/** @scrutinizer ignore-call */ getOperationSetting('tabsEnabled');
Loading history...
28
    }
29
30
    /**
31
     * @return bool
32
     */
33
    public function tabsDisabled()
34
    {
35
        return ! $this->tabsEnabled();
36
    }
37
38
    public function setTabsType($type)
39
    {
40
        $this->enableTabs();
41
        $this->setOperationSetting('tabsType', $type);
42
43
        return $this->getOperationSetting('tabsType');
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getTabsType()
50
    {
51
        return $this->getOperationSetting('tabsType');
52
    }
53
54
    public function enableVerticalTabs()
55
    {
56
        return $this->setTabsType('vertical');
57
    }
58
59
    public function disableVerticalTabs()
60
    {
61
        return $this->setTabsType('horizontal');
62
    }
63
64
    public function enableHorizontalTabs()
65
    {
66
        return $this->setTabsType('horizontal');
67
    }
68
69
    public function disableHorizontalTabs()
70
    {
71
        return $this->setTabsType('vertical');
72
    }
73
74
    /**
75
     * @param  string  $label
76
     * @return bool
77
     */
78
    public function tabExists($label)
79
    {
80
        $tabs = $this->getTabs();
81
82
        return in_array($label, $tabs);
83
    }
84
85
    /**
86
     * @return bool|string
87
     */
88
    public function getLastTab()
89
    {
90
        $tabs = $this->getTabs();
91
92
        if (count($tabs)) {
93
            return last($tabs);
94
        }
95
96
        return false;
97
    }
98
99
    /**
100
     * @param $label
101
     * @return bool
102
     */
103
    public function isLastTab($label)
104
    {
105
        return $this->getLastTab() == $label;
106
    }
107
108
    /**
109
     * @deprecated Do not use this method as it will be removed in future versions!
110
     * Instead, use $this->getElementsWithoutATab($this->getCurrentFields())
111
     *
112
     * @return \Illuminate\Support\Collection
113
     */
114
    public function getFieldsWithoutATab()
115
    {
116
        return $this->getElementsWithoutATab($this->getCurrentFields());
0 ignored issues
show
Bug introduced by
The method getCurrentFields() does not exist on Backpack\CRUD\app\Library\CrudPanel\Traits\Tabs. Did you maybe mean getCurrentItems()? ( Ignorable by Annotation )

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

116
        return $this->getElementsWithoutATab($this->/** @scrutinizer ignore-call */ getCurrentFields());

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...
117
    }
118
119
    /**
120
     * @return \Illuminate\Support\Collection
121
     */
122
    public function getElementsWithoutATab(array $elements)
123
    {
124
        return collect($elements)->filter(function ($value) {
0 ignored issues
show
Bug introduced by
$elements of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

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

124
        return collect(/** @scrutinizer ignore-type */ $elements)->filter(function ($value) {
Loading history...
125
            return ! isset($value['tab']);
126
        });
127
    }
128
129
    /**
130
     * @return array|\Illuminate\Support\Collection
131
     */
132
    public function getTabFields(string $label)
133
    {
134
        return $this->getTabItems($label, 'fields');
135
    }
136
137
    /**
138
     * @return array|\Illuminate\Support\Collection
139
     */
140
    public function getTabColumns(string $label)
141
    {
142
        return $this->getTabItems($label, 'columns');
143
    }
144
145
    /**
146
     * @return array|\Illuminate\Support\Collection
147
     */
148
    public function getTabItems(string $label, string $source)
149
    {
150
        if (in_array($label, $this->getUniqueTabNames($source))) {
151
            $items = $this->getCurrentItems($source);
152
            return collect($items)->filter(function ($value) use ($label) {
0 ignored issues
show
Bug introduced by
$items of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

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

152
            return collect(/** @scrutinizer ignore-type */ $items)->filter(function ($value) use ($label) {
Loading history...
153
                return isset($value['tab']) && $value['tab'] == $label;
154
            });
155
        }
156
157
        return [];
158
    }
159
160
    public function getTabs(): array
161
    {
162
        return $this->getUniqueTabNames('fields');
163
    }
164
165
    /**
166
     * $source could be `fields` or `columns` for now.
167
     */
168
    public function getUniqueTabNames(string $source): array
169
    {
170
        $tabs = [];
171
        $items = $this->getCurrentItems($source);
172
173
        collect($items)
0 ignored issues
show
Bug introduced by
$items of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

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

173
        collect(/** @scrutinizer ignore-type */ $items)
Loading history...
174
            ->filter(function ($value) {
175
                return isset($value['tab']);
176
            })
177
            ->each(function ($value) use (&$tabs) {
178
                if (! in_array($value['tab'], $tabs)) {
179
                    $tabs[] = $value['tab'];
180
                }
181
            });
182
183
        return $tabs;
184
    }
185
186
    public function getCurrentItems(string $source): array
187
    {
188
        $items = [];
189
190
        switch ($source) {
191
            case 'fields':
192
                $items = $this->getCurrentFields();
193
                break;
194
            case 'columns':
195
                $items = $this->columns();
0 ignored issues
show
Bug introduced by
It seems like columns() 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

195
                /** @scrutinizer ignore-call */ 
196
                $items = $this->columns();
Loading history...
196
                break;
197
            default:
198
                break;
199
        }
200
201
        return $items;
202
    }
203
}
204