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
Push — master ( 414922...a9bc98 )
by butschster
12:35
created

ControlLink::getConditionAttributes()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 13
rs 9.2
c 4
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Display;
4
5
use Closure;
6
use Illuminate\Contracts\View\View;
7
use Illuminate\Database\Eloquent\Model;
8
use KodiComponents\Support\HtmlAttributes;
9
use SleepingOwl\Admin\Contracts\Display\ControlButtonInterface;
10
11
class ControlLink implements ControlButtonInterface
12
{
13
    use HtmlAttributes;
14
15
    /**
16
     * @var Closure
17
     */
18
    protected $url;
19
20
    /**
21
     * @var Closure
22
     */
23
    protected $attributeCondition;
24
25
    /**
26
     * @var int
27
     */
28
    protected $position;
29
30
    /**
31
     * @var string|View
32
     */
33
    protected $view = 'column.control_link';
34
35
    /**
36
     * @var string
37
     */
38
    protected $text;
39
40
    /**
41
     * @var bool
42
     */
43
    protected $hideText = false;
44
45
    /**
46
     * @var string
47
     */
48
    protected $icon;
49
50
    /**
51
     * @var Model
52
     */
53
    protected $model;
54
55
    /**
56
     * @var Closure
57
     */
58
    protected $condition;
59
60
    /**
61
     * ControlButton constructor.
62
     *
63
     * @param Closure $url
64
     * @param string $text
65
     * @param int $position
66
     */
67
    public function __construct(Closure $url, $text, $position = 0)
68
    {
69
        $this->url = $url;
70
        $this->position = (int) $position;
71
        $this->text = $text;
72
73
        $this->setHtmlAttributes([
74
            'class' => 'btn btn-xs',
75
            'title' => $this->text,
76
            'data-toggle' => 'tooltip',
77
        ]);
78
    }
79
80
    /**
81
     * @return bool|mixed
82
     */
83
    public function isActive()
84
    {
85
        return $this->condition ? call_user_func($this->condition, $this->model) : true;
86
    }
87
88
    /**
89
     * @param Model $model
90
     * @return $this
91
     */
92
    public function getConditionAttributes(Model $model)
93
    {
94
        $temp = $this->attributeCondition ? call_user_func($this->attributeCondition, $model) : [];
95
96
        if ($temp) {
97
            foreach ($temp as $key => $value) {
98
                $this->removeHtmlAttribute($key);
99
                $this->setHtmlAttribute($key, $value);
100
            }
101
        }
102
103
        return $this;
104
    }
105
106
    /**
107
     * @param Closure $condition
108
     *
109
     * @return $this
110
     */
111
    public function setCondition(Closure $condition)
112
    {
113
        $this->condition = $condition;
114
115
        return $this;
116
    }
117
118
    /**
119
     * Set condition attribute.
120
     * @param Closure $condition
121
     *
122
     * @return $this
123
     */
124
    public function setAttributeCondition(Closure $condition)
125
    {
126
        $this->attributeCondition = $condition;
127
128
        return $this;
129
    }
130
131
    /**
132
     * @return $this
133
     */
134
    public function hideText()
135
    {
136
        $this->hideText = true;
137
138
        return $this;
139
    }
140
141
    /**
142
     * @return int
143
     */
144
    public function getPosition()
145
    {
146
        return $this->position;
147
    }
148
149
    /**
150
     * @param Closure $closure
151
     *
152
     * @return $this
153
     */
154
    public function setUrl(Closure $closure)
155
    {
156
        $this->url = $closure;
157
158
        return $this;
159
    }
160
161
    /**
162
     * @param Model $model
163
     *
164
     * @return mixed
165
     */
166
    public function getUrl(Model $model)
167
    {
168
        return call_user_func($this->url, $model);
169
    }
170
171
    /**
172
     * @return View|string
173
     */
174
    public function getView()
175
    {
176
        return $this->view;
177
    }
178
179
    /**
180
     * @param string $text
181
     *
182
     * @return $this
183
     */
184
    public function setText($text)
185
    {
186
        $this->text = $text;
187
188
        return $this;
189
    }
190
191
    /**
192
     * @return string
193
     */
194
    public function getIcon()
195
    {
196
        return $this->icon;
197
    }
198
199
    /**
200
     * @param string $icon
201
     *
202
     * @return $this
203
     */
204
    public function setIcon($icon)
205
    {
206
        $this->icon = $icon;
207
208
        return $this;
209
    }
210
211
    /**
212
     * @param Model $model
213
     *
214
     * @return $this
215
     */
216
    public function setModel(Model $model)
217
    {
218
        $this->model = $model;
219
220
        return $this;
221
    }
222
223
    /**
224
     * Get the instance as an array.
225
     *
226
     * @return array
227
     */
228
    public function toArray()
229
    {
230
        return [
231
            'attributes' => $this->getConditionAttributes($this->model)->htmlAttributesToString(),
232
            'url' => $this->getUrl($this->model),
233
            'position' => $this->getPosition(),
234
            'text' => $this->text,
235
            'icon' => $this->getIcon(),
236
            'hideText' => $this->hideText,
237
        ];
238
    }
239
240
    /**
241
     * @return string
242
     */
243
    public function __toString()
244
    {
245
        return (string) $this->render();
246
    }
247
248
    /**
249
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
250
     */
251
    public function render()
252
    {
253
        return app('sleeping_owl.template')->view(
254
            $this->getView(),
255
            $this->toArray()
256
        )->render();
257
    }
258
}
259