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

Completed
Push — master ( bab703...dad563 )
by Cristian
08:35
created

Tabs::tabsDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\PanelTraits;
4
5
trait Tabs
6
{
7
    public $tabsEnabled = false;
8
    public $tabsType = 'horizontal';
9
10 9
    public function enableTabs()
11
    {
12 9
        $this->tabsEnabled = true;
13 9
        $this->setTabsType(config('backpack.crud.tabs_type', 'horizontal'));
14
15 9
        return $this->tabsEnabled;
16
    }
17
18 2
    public function disableTabs()
19
    {
20 2
        $this->tabsEnabled = false;
21
22 2
        return $this->tabsEnabled;
23
    }
24
25 8
    public function tabsEnabled()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
26
    {
27 8
        return $this->tabsEnabled;
28
    }
29
30 1
    public function tabsDisabled()
31
    {
32 1
        return ! $this->tabsEnabled;
33
    }
34
35 14
    public function setTabsType($type)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
36
    {
37 14
        $this->tabsType = $type;
38
39 14
        return $this->tabsType;
40
    }
41
42 5
    public function getTabsType()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
43
    {
44 5
        return $this->tabsType;
45
    }
46
47 1
    public function enableVerticalTabs()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
48
    {
49 1
        return $this->setTabsType('vertical');
50
    }
51
52 1
    public function disableVerticalTabs()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
53
    {
54 1
        return $this->setTabsType('horizontal');
55
    }
56
57 1
    public function enableHorizontalTabs()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
58
    {
59 1
        return $this->setTabsType('horizontal');
60
    }
61
62 1
    public function disableHorizontalTabs()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
63
    {
64 1
        return $this->setTabsType('vertical');
65
    }
66
67 3
    public function tabExists($label)
68
    {
69 3
        $tabs = $this->getTabs();
70
71 3
        return in_array($label, $tabs);
72
    }
73
74 4
    public function getLastTab()
75
    {
76 4
        $tabs = $this->getTabs();
77
78 4
        if (count($tabs)) {
79 3
            return last($tabs);
80
        }
81
82 1
        return false;
83
    }
84
85 2
    public function isLastTab($label)
86
    {
87 2
        return $this->getLastTab() == $label;
88
    }
89
90 1
    public function getTabFields($label)
91
    {
92 1
        if ($this->tabExists($label)) {
93
            $all_fields = $this->getCurrentFields();
0 ignored issues
show
Bug introduced by
It seems like getCurrentFields() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
94
95
            $fields_for_current_tab = collect($all_fields)->filter(function ($value, $key) use ($label) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
                return isset($value['tab']) && $value['tab'] == $label;
97
            });
98
99
            if ($this->isLastTab($label)) {
100
                $fields_without_a_tab = collect($all_fields)->filter(function ($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
                    return ! isset($value['tab']);
102
                });
103
104
                $fields_for_current_tab = $fields_for_current_tab->merge($fields_without_a_tab);
105
            }
106
107
            return $fields_for_current_tab;
108
        }
109
110 1
        return [];
111
    }
112
113 9
    public function getTabs()
114
    {
115 9
        $tabs = [];
116 9
        $fields = $this->getCurrentFields();
0 ignored issues
show
Bug introduced by
It seems like getCurrentFields() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
117
118 9
        $fields_with_tabs = collect($fields)
0 ignored issues
show
Unused Code introduced by
$fields_with_tabs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
119
            ->filter(function ($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
120 7
                return isset($value['tab']);
121 9
            })
122 9
            ->each(function ($value, $key) use (&$tabs) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
123 7
                if (! in_array($value['tab'], $tabs)) {
124 7
                    $tabs[] = $value['tab'];
125 7
                }
126 9
            });
127
128 9
        return $tabs;
129
    }
130
}
131