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
Pull Request — master (#487)
by Julien
03:21
created

Tabs::boxHasTabs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
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
    public function enableTabs()
11
    {
12
        $this->tabsEnabled = true;
13
        $this->setTabsType(config('backpack.crud.tabs_type', 'horizontal'));
14
15
        return $this->tabsEnabled;
16
    }
17
18
    public function disableTabs()
19
    {
20
        $this->tabsEnabled = false;
21
22
        return $this->tabsEnabled;
23
    }
24
25
    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
        return $this->tabsEnabled;
28
    }
29
30
    public function tabsDisabled()
31
    {
32
        return ! $this->tabsEnabled;
33
    }
34
35
    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
        $this->tabsType = $type;
38
39
        return $this->tabsType;
40
    }
41
42
    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
        return $this->tabsType;
45
    }
46
47
    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
        return $this->setTabsType('vertical');
50
    }
51
52
    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
        return $this->setTabsType('horizontal');
55
    }
56
57
    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
        return $this->setTabsType('horizontal');
60
    }
61
62
    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
        return $this->setTabsType('vertical');
65
    }
66
67
    public function boxHasTabs($boxLabel)
68
    {
69
        return $this->tabsEnabled() && count($this->getTabs($boxLabel)) > 0;
70
    }
71
72
    public function tabExists($boxLabel, $tabLabel)
73
    {
74
        $tabs = $this->getTabs($boxLabel);
75
76
        return in_array($tabLabel, $tabs);
77
    }
78
79
    public function getLastTab($boxLabel)
80
    {
81
        $tabs = $this->getTabs($boxLabel);
82
83
        if (count($tabs)) {
84
            return last($tabs);
85
        }
86
87
        return false;
88
    }
89
90
    public function isLastTab($boxLabel, $tabLabel)
91
    {
92
        return $this->getLastTab($boxLabel) == $tabLabel;
93
    }
94
95
    public function getTabFields($boxLabel, $tabLabel)
96
    {
97
        if ($this->boxExists($boxLabel) && $this->tabExists($boxLabel, $tabLabel)) {
0 ignored issues
show
Bug introduced by
It seems like boxExists() 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...
98
            $boxFields = $this->getBoxFields($boxLabel);
0 ignored issues
show
Bug introduced by
It seems like getBoxFields() 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...
99
100
            $fields_for_current_tab = collect($boxFields)->filter(function ($value, $key) use ($tabLabel) {
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']) && $value['tab'] == $tabLabel;
102
            });
103
104 View Code Duplication
            if ($this->isLastTab($boxLabel, $tabLabel)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
                $fields_without_a_tab = collect($boxFields)->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...
106
                    return ! isset($value['tab']);
107
                });
108
109
                $fields_for_current_tab = $fields_for_current_tab->merge($fields_without_a_tab);
110
            }
111
112
            return $fields_for_current_tab;
113
        }
114
115
        return [];
116
    }
117
118
    public function getTabs($boxLabel)
119
    {
120
        $tabs = [];
121
        $fields = $this->getBoxFields($boxLabel);
0 ignored issues
show
Bug introduced by
It seems like getBoxFields() 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...
122
123
        $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...
124
            ->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...
125
                return isset($value['tab']);
126
            })
127
            ->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...
128
                if (! in_array($value['tab'], $tabs)) {
129
                    $tabs[] = $value['tab'];
130
                }
131
            });
132
133
        return $tabs;
134
    }
135
}
136