GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch development (1ea943)
by butschster
05:38
created

Tree::setView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Display\Extension;
4
5
use Illuminate\Support\Collection;
6
use KodiComponents\Support\HtmlAttributes;
7
use Illuminate\Contracts\Support\Renderable;
8
use SleepingOwl\Admin\Display\Column\Control;
9
use SleepingOwl\Admin\Contracts\Initializable;
10
use SleepingOwl\Admin\Contracts\ColumnInterface;
11
12
class Tree extends Extension implements Initializable, Renderable
13
{
14
    use HtmlAttributes, \SleepingOwl\Admin\Traits\Renderable;
15
16
    /**
17
     * @var bool
18
     */
19
    protected $controlActive = true;
20
21
    /**
22
     * @var string|\Illuminate\View\View
23
     */
24
    protected $view = 'display.columns';
25
26
    /**
27
     * @var Control
28
     */
29
    protected $controlColumn;
30
31
    public function __construct()
32
    {
33
        $this->columns = new Collection();
0 ignored issues
show
Bug introduced by
The property columns does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
35
        $this->setControlColumn(app('sleeping_owl.table.column')->treeControl());
36
    }
37
38
    /**
39
     * @param ColumnInterface $controlColumn
40
     *
41
     * @return $this
42
     */
43
    public function setControlColumn(ColumnInterface $controlColumn)
44
    {
45
        $this->controlColumn = $controlColumn;
0 ignored issues
show
Documentation Bug introduced by
$controlColumn is of type object<SleepingOwl\Admin...tracts\ColumnInterface>, but the property $controlColumn was declared to be of type object<SleepingOwl\Admin\Display\Column\Control>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
46
47
        return $this;
48
    }
49
50
    /**
51
     * @return Control
52
     */
53
    public function getControlColumn()
54
    {
55
        return $this->controlColumn;
56
    }
57
58
    /**
59
     * @return bool
60
     */
61
    public function isControlActive()
62
    {
63
        return $this->controlActive;
64
    }
65
66
    /**
67
     * @return $this
68
     */
69
    public function enableControls()
70
    {
71
        $this->controlActive = true;
72
73
        return $this;
74
    }
75
76
    /**
77
     * @return $this
78
     */
79
    public function disableControls()
80
    {
81
        $this->controlActive = true;
82
83
        return $this;
84
    }
85
86
    /**
87
     * @return Collection|\SleepingOwl\Admin\Contracts\ColumnInterface[]
88
     */
89
    public function all()
90
    {
91
        return $this->columns;
92
    }
93
94
    /**
95
     * @return Collection|\SleepingOwl\Admin\Contracts\ColumnInterface[]
96
     */
97
    public function allWithControl()
98
    {
99
        $columns = $this->all();
100
101
        if ($this->isControlActive()) {
102
            $columns->push($this->getControlColumn());
103
        }
104
105
        return $columns;
106
    }
107
108
    /**
109
     * @param ColumnInterface $column
110
     *
111
     * @return $this
112
     */
113
    public function push(ColumnInterface $column)
114
    {
115
        $this->columns->push($column);
116
117
        return $this;
118
    }
119
120
    /**
121
     * Get the instance as an array.
122
     *
123
     * @return array
124
     */
125
    public function toArray()
126
    {
127
        return [
128
            'columns'    => $this->allWithControl(),
129
            'attributes' => $this->htmlAttributesToString(),
130
        ];
131
    }
132
133
    public function initialize()
134
    {
135
        $this->allWithControl()->each(function (ColumnInterface $column) {
136
            $column->initialize();
137
        });
138
139
        $this->setHtmlAttribute('class', 'table table-striped');
140
    }
141
}
142