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 — analysis-m4VopE ( 4da4ca )
by butschster
12:05
created

FormElement::isVisible()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Form;
4
5
use Closure;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Http\Request;
8
use Illuminate\Validation\Rules\Dimensions;
9
use Illuminate\Validation\Rules\Exists;
10
use Illuminate\Validation\Rules\In;
11
use Illuminate\Validation\Rules\NotIn;
12
use Illuminate\Validation\Rules\Unique;
13
use SleepingOwl\Admin\Contracts\Form\FormElementInterface;
14
use SleepingOwl\Admin\Contracts\Template\TemplateInterface;
15
use SleepingOwl\Admin\Traits\Assets;
16
use SleepingOwl\Admin\Traits\Renderable;
17
use SleepingOwl\Admin\Traits\Visibled;
18
19
abstract class FormElement implements FormElementInterface
20
{
21
    use Assets, Renderable, Visibled;
22
23
    /**
24
     * @var TemplateInterface
25
     */
26
    protected $template;
27
28
    /**
29
     * @var Renderable
30
     */
31
    protected $view;
32
33
    /**
34
     * @var Model
35
     */
36
    protected $model;
37
38
    /**
39
     * @var array
40
     */
41
    protected $validationRules = [];
42
43
    /**
44
     * @var array
45
     */
46
    protected $validationMessages = [];
47
48
    /**
49
     * @var bool|callable
50
     */
51
    protected $readonly = false;
52
53
    /**
54
     * @var bool|callable
55
     */
56
    protected $valueSkipped = false;
57
58
    /**
59
     * @var mixed
60
     */
61
    protected $value;
62
63
    public function __construct()
64
    {
65
        $this->initializePackage();
66
    }
67
68
    public function initialize()
69
    {
70
        $this->includePackage();
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function getValidationMessages()
77
    {
78
        return $this->validationMessages;
79
    }
80
81
    /**
82
     * @param string $rule
83
     * @param string $message
84
     *
85
     * @return $this
86
     */
87
    public function addValidationMessage($rule, $message)
88
    {
89
        if (($pos = strpos($rule, ':')) !== false) {
90
            $rule = substr($rule, 0, $pos);
91
        }
92
93
        $this->validationMessages[$rule] = $message;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @param array $validationMessages
100
     *
101
     * @return $this
102
     */
103
    public function setValidationMessages(array $validationMessages)
104
    {
105
        $this->validationMessages = $validationMessages;
106
107
        return $this;
108
    }
109
110
    /**
111
     * @return array
112
     */
113
    public function getValidationLabels()
114
    {
115
        return [];
116
    }
117
118
    /**
119
     * @return array
120
     */
121
    public function getValidationRules()
122
    {
123
        return $this->validationRules;
124
    }
125
126
    /**
127
     * @param string $rule
128
     * @param string|null $message
129
     *
130
     * @return $this
131
     */
132
    public function addValidationRule($rule, $message = null)
133
    {
134
        $this->validationRules[] = $rule;
135
136
        if (is_null($message)) {
137
            return $this;
138
        }
139
140
        return $this->addValidationMessage($rule, $message);
141
    }
142
143
    /**
144
     * @param array|string $validationRules
145
     * @param string|\Illuminate\Validation\Rule|\Illuminate\Contracts\Validation\Rule $rule
146
     *
147
     * @return $this
148
     */
149
    public function setValidationRules($validationRules)
150
    {
151
        if (! is_array($validationRules)) {
152
            $validationRules = func_get_args();
153
        }
154
155
        $this->validationRules = [];
156
        foreach ($validationRules as $rule) {
157
            if ($rule instanceof \Illuminate\Validation\Rule || $rule instanceof \Illuminate\Contracts\Validation\Rule || $rule instanceof Dimensions || $rule instanceof Exists || $rule instanceof In || $rule instanceof NotIn || $rule instanceof Unique) {
158
                $this->addValidationRule($rule);
0 ignored issues
show
Bug introduced by
It seems like $rule can also be of type Illuminate\Contracts\Validation\Rule and Illuminate\Validation\Rule; however, parameter $rule of SleepingOwl\Admin\Form\F...nt::addValidationRule() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

158
                $this->addValidationRule(/** @scrutinizer ignore-type */ $rule);
Loading history...
159
            } else {
160
                $rules = explode('|', $rule);
161
                foreach ($rules as $addRule) {
162
                    $this->addValidationRule($addRule);
163
                }
164
            }
165
        }
166
167
        return $this;
168
    }
169
170
    /**
171
     * @return Model
172
     */
173
    public function getModel()
174
    {
175
        return $this->model;
176
    }
177
178
    /**
179
     * @param Model $model
180
     *
181
     * @return $this
182
     */
183
    public function setModel(Model $model)
184
    {
185
        $this->model = $model;
186
187
        return $this;
188
    }
189
190
    /**
191
     * @return bool|callable
192
     */
193
    public function isReadonly()
194
    {
195
        if (is_callable($this->readonly)) {
196
            return (bool) call_user_func($this->readonly, $this->getModel());
0 ignored issues
show
Bug introduced by
It seems like $this->readonly can also be of type boolean; however, parameter $function of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

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

196
            return (bool) call_user_func(/** @scrutinizer ignore-type */ $this->readonly, $this->getModel());
Loading history...
197
        }
198
199
        return (bool) $this->readonly;
200
    }
201
202
    /**
203
     * @return bool
204
     */
205
    public function isValueSkipped()
206
    {
207
        if (is_callable($this->valueSkipped)) {
208
            return (bool) call_user_func($this->valueSkipped, $this->getModel());
0 ignored issues
show
Bug introduced by
It seems like $this->valueSkipped can also be of type boolean; however, parameter $function of call_user_func() does only seem to accept callable, maybe add an additional type check? ( Ignorable by Annotation )

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

208
            return (bool) call_user_func(/** @scrutinizer ignore-type */ $this->valueSkipped, $this->getModel());
Loading history...
209
        }
210
211
        return (bool) $this->valueSkipped;
212
    }
213
214
    /**
215
     * @param Closure|bool $valueSkipped
216
     *
217
     * @return $this
218
     */
219
    public function setValueSkipped($valueSkipped)
220
    {
221
        $this->valueSkipped = $valueSkipped;
222
223
        return $this;
224
    }
225
226
    /**
227
     * @param Closure|bool $readonly
228
     *
229
     * @return $this
230
     */
231
    public function setReadonly($readonly)
232
    {
233
        $this->readonly = $readonly;
234
235
        return $this;
236
    }
237
238
    /**
239
     * @return mixed
240
     */
241
    public function getValue()
242
    {
243
        return $this->value;
244
    }
245
246
    /**
247
     * @param mixed $value
248
     *
249
     * @return $this
250
     */
251
    public function setValue($value)
252
    {
253
        $this->value = $value;
254
255
        return $this;
256
    }
257
258
    /**
259
     * @param Request $request
260
     *
261
     * @return void
262
     */
263
    public function save(Request $request)
264
    {
265
    }
266
267
    /**
268
     * @param Request $request
269
     *
270
     * @return void
271
     */
272
    public function afterSave(Request $request)
273
    {
274
    }
275
276
    /**
277
     * @return array
278
     */
279
    public function toArray()
280
    {
281
        return [
282
            'value' => $this->getValue(),
283
            'readonly' => $this->isReadonly(),
284
            'visibled' => $this->getVisibled(),
285
            'model' => $this->getModel(),
286
        ];
287
    }
288
}
289