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.

Issues (389)

Branch: master

src/Model/ModelConfiguration.php (9 issues)

1
<?php
2
3
namespace SleepingOwl\Admin\Model;
4
5
use Closure;
6
use Illuminate\Database\Eloquent\Model;
7
use SleepingOwl\Admin\Contracts\Display\DisplayInterface;
8
use SleepingOwl\Admin\Contracts\Form\FormInterface;
9
use SleepingOwl\Admin\Contracts\Initializable;
10
use SleepingOwl\Admin\Display\DisplayDatatablesAsync;
11
12
class ModelConfiguration extends ModelConfigurationManager
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $createTitle;
18
19
    /**
20
     * @var string
21
     */
22
    protected $editTitle;
23
24
    /**
25
     * @var Closure|null
26
     */
27
    protected $display;
28
29
    /**
30
     * @var Closure|null
31
     */
32
    protected $create;
33
34
    /**
35
     * @var bool
36
     */
37
    protected $displayable = true;
38
39
    /**
40
     * @var bool
41
     */
42
    protected $creatable = true;
43
44
    /**
45
     * @var bool
46
     */
47
    protected $editable = true;
48
49
    /**
50
     * @var bool
51
     */
52
    protected $restorable = true;
53
54
    /**
55
     * @var bool
56
     */
57
    protected $deletable = true;
58
59
    /**
60
     * @var bool
61
     */
62
    protected $destroyable = true;
63
64
    /**
65
     * @var Closure|null
66
     */
67
    protected $edit;
68
69
    /**
70
     * @var Closure|null
71
     */
72
    protected $delete = true;
73
74
    /**
75
     * @var Closure|null
76
     */
77
    protected $destroy = true;
78
79
    /**
80
     * @var Closure|null
81
     */
82
    protected $restore = true;
83
84
    /**
85
     * @var string
86
     */
87
    protected $messageOnCreate;
88
89
    /**
90
     * @var string
91
     */
92
    protected $messageOnUpdate;
93
94
    /**
95
     * @var string
96
     */
97
    protected $messageOnDelete;
98
99
    /**
100
     * @var string
101
     */
102
    protected $messageOnDestroy;
103
104
    /**
105
     * @var string
106
     */
107
    protected $messageOnRestore;
108
109
    protected $breadcrumbs = null;
110
111 27
    public function __construct(\Illuminate\Contracts\Foundation\Application $app, $class)
112
    {
113 27
        parent::__construct($app, $class);
114 27
        $this->breadcrumbs = collect();
115 27
    }
116
117
    /**
118
     * @return \Illuminate\Support\Collection|null
119
     */
120
    public function getBreadCrumbs()
121
    {
122
        return $this->breadcrumbs->toArray();
123
    }
124
125
    /**
126
     * @param $breadcrumb
127
     * @return mixed|void
128
     */
129
    public function addBreadCrumb($breadcrumb)
130
    {
131
        $this->breadcrumbs->push($breadcrumb);
132
    }
133
134
    /**
135
     * @param string $alias
136
     *
137
     * @return $this
138
     */
139 1
    public function setAlias($alias)
140
    {
141 1
        $this->alias = $alias;
142
143 1
        return $this;
144
    }
145
146
    /**
147
     * @param string $title
148
     *
149
     * @return $this
150
     */
151 1
    public function setTitle($title)
152
    {
153 1
        $this->title = $title;
154
155 1
        return $this;
156
    }
157
158
    /**
159
     * @return string|\Symfony\Component\Translation\TranslatorInterface
160
     */
161 1
    public function getCreateTitle()
162
    {
163 1
        if (is_null($this->createTitle)) {
0 ignored issues
show
The condition is_null($this->createTitle) is always false.
Loading history...
164 1
            return parent::getCreateTitle();
165
        }
166
167 1
        return $this->createTitle;
168
    }
169
170
    /**
171
     * @param string $title
172
     *
173
     * @return $this
174
     */
175 1
    public function setCreateTitle($title)
176
    {
177 1
        $this->createTitle = $title;
178
179 1
        return $this;
180
    }
181
182
    /**
183
     * @param Model $model
184
     * @return string|\Symfony\Component\Translation\TranslatorInterface
185 1
     */
186
    public function getEditTitle()
187 1
    {
188 1
        if (is_null($this->editTitle)) {
0 ignored issues
show
The condition is_null($this->editTitle) is always false.
Loading history...
189
            return parent::getEditTitle();
190
        }
191 1
192
        return $this->editTitle;
193
    }
194
195
    /**
196
     * @param string $title
197
     *
198
     * @return $this
199 1
     */
200
    public function setEditTitle($title)
201 1
    {
202
        $this->editTitle = $title;
203 1
204
        return $this;
205
    }
206
207
    /**
208
     * @return bool
209 1
     */
210
    public function isDisplayable()
211 1
    {
212
        return $this->displayable && parent::isDisplayable();
213
    }
214
215
    /**
216
     * @return $this
217 1
     */
218
    public function disableDisplay()
219 1
    {
220
        $this->displayable = false;
221 1
222
        return $this;
223
    }
224
225
    /**
226
     * @param string $action
227
     * @param \Illuminate\Database\Eloquent\Model $model
228
     *
229
     * @return bool
230 6
     */
231
    public function can($action, Model $model)
232 6
    {
233 6
        if (! $this->checkAccess) {
234
            return true;
235
        }
236
237
        return \Gate::allows($action, $model);
238
    }
239
240
    /**
241
     * @return bool
242 1
     */
243
    public function isCreatable()
244 1
    {
245 1
        if (! is_callable($this->getCreate())) {
246
            return false;
247
        }
248 1
249
        return $this->creatable && parent::isCreatable($this->getModel());
0 ignored issues
show
The call to SleepingOwl\Admin\Model\...nManager::isCreatable() has too many arguments starting with $this->getModel(). ( Ignorable by Annotation )

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

249
        return $this->creatable && parent::/** @scrutinizer ignore-call */ isCreatable($this->getModel());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
250
    }
251
252
    /**
253
     * @return $this
254 1
     */
255
    public function disableCreating()
256 1
    {
257
        $this->creatable = false;
258 1
259
        return $this;
260
    }
261
262
    /**
263
     * @param Model $model
264
     *
265
     * @return bool
266 1
     */
267
    public function isEditable(Model $model)
268 1
    {
269 1
        if (! is_callable($this->getEdit())) {
270
            return false;
271
        }
272 1
273
        return $this->editable && parent::isEditable($model);
274
    }
275
276
    /**
277
     * @return $this
278 1
     */
279
    public function disableEditing()
280 1
    {
281
        $this->editable = false;
282 1
283
        return $this;
284
    }
285
286
    /**
287
     * @param bool $deletable
288
     *
289
     * @return $this
290 1
     */
291
    public function setDeletable($deletable)
292 1
    {
293
        $this->deletable = (bool) $deletable;
294 1
295
        return $this;
296
    }
297
298
    /**
299
     * @param Model $model
300
     *
301
     * @return bool
302 1
     */
303
    public function isDeletable(Model $model)
304 1
    {
305
        return $this->deletable && parent::isDeletable($model);
306
    }
307
308
    /**
309
     * @return $this
310 1
     */
311
    public function disableDeleting()
312 1
    {
313
        $this->setDeletable(false);
314 1
315
        return $this;
316
    }
317
318
    /**
319
     * @param Model $model
320
     *
321
     * @return bool
322 3
     */
323
    public function isDestroyable(Model $model)
324 3
    {
325
        return $this->destroyable && parent::isDestroyable($model);
326
    }
327
328
    /**
329
     * @return $this
330 1
     */
331
    public function disableDestroying()
332 1
    {
333
        $this->destroyable = false;
334 1
335
        return $this;
336
    }
337
338
    /**
339
     * @param Model $model
340
     *
341
     * @return bool
342 1
     */
343
    public function isRestorable(Model $model)
344 1
    {
345
        return $this->restorable && parent::isRestorable($model);
346
    }
347
348
    /**
349
     * @return bool
350 6
     */
351
    public function isRestorableModel()
352 6
    {
353
        return $this->restorable && parent::isRestorableModel();
354
    }
355
356
    /**
357
     * @return $this
358 1
     */
359
    public function disableRestoring()
360 1
    {
361
        $this->restorable = false;
362 1
363
        return $this;
364
    }
365
366
    /**
367
     * @return Closure|null
368 1
     */
369
    public function getDisplay()
370 1
    {
371
        return $this->display;
372
    }
373
374
    /**
375
     * @param Closure $callback
376
     *
377
     * @return $this
378 1
     */
379
    public function onDisplay(Closure $callback)
380 1
    {
381
        $this->display = $callback;
382 1
383
        return $this;
384
    }
385
386
    /**
387
     * @param mixed $payload
388
     * @return DisplayInterface|mixed|void
389 1
     */
390
    public function fireDisplay($payload = [])
391 1
    {
392
        if (! is_callable($this->getDisplay())) {
393
            return;
394
        }
395 1
396
        $display = $this->app->call($this->getDisplay(), ['payload' => $payload]);
397 1
398
        if ($display instanceof DisplayDatatablesAsync) {
399
            $display->setPayload($payload);
400
        }
401 1
402 1
        if ($display instanceof DisplayInterface) {
403 1
            $display->setModelClass($this->getClass());
404
        }
405 1
406 1
        if ($display instanceof Initializable) {
407 1
            $display->initialize();
408
        }
409 1
410
        return $display;
411
    }
412
413
    /**
414
     * @return Closure|null
415 3
     */
416
    public function getCreate()
417 3
    {
418
        return $this->create;
419
    }
420
421
    /**
422
     * @param Closure|null $callback
423
     *
424
     * @return $this
425 3
     */
426
    public function onCreate(Closure $callback = null)
427 3
    {
428
        $this->create = $callback;
429 3
430
        return $this;
431
    }
432
433
    /**
434
     * @param mixed $payload
435 1
     * @return mixed|void
436
     */
437 1
    public function fireCreate($payload = [])
438
    {
439
        if (! is_callable($this->getCreate())) {
440
            return;
441 1
        }
442 1
443 1
        $form = $this->app->call($this->getCreate(), ['payload' => $payload]);
444 1
445
        if ($form instanceof DisplayInterface) {
446 1
            $form->setModelClass($this->getClass());
447 1
        }
448 1
449
        if ($form instanceof FormInterface) {
450 1
            $form->setAction($this->getStoreUrl());
451 1
        }
452 1
453
        if ($form instanceof Initializable) {
454 1
            $form->initialize();
455
        }
456
457
        return $form;
458
    }
459
460 3
    /**
461
     * @return Closure|null
462 3
     */
463
    public function getEdit()
464
    {
465
        return $this->edit;
466
    }
467
468
    /**
469
     * @param Closure|null $callback
470 3
     *
471
     * @return $this
472 3
     */
473
    public function onEdit(Closure $callback = null)
474 3
    {
475
        $this->edit = $callback;
476
477
        return $this;
478
    }
479
480
    /**
481
     * @param int|string $id
482 1
     * @param mixed $payload
483
     * @return mixed|void
484 1
     */
485
    public function fireEdit($id, $payload = [])
486
    {
487
        if (! is_callable($this->getEdit())) {
488 1
            return;
489 1
        }
490 1
491 1
        $payload = array_merge(['id' => $id], ['payload' => $payload]);
492
493 1
        $form = $this->app->call($this->getEdit(), $payload);
494 1
495 1
        if ($form instanceof DisplayInterface) {
496
            $form->setModelClass($this->getClass());
497 1
        }
498 1
499 1
        if ($form instanceof FormInterface) {
500
            $form->setAction($this->getUpdateUrl($id));
501 1
        }
502 1
503 1
        if ($form instanceof Initializable) {
504
            $form->initialize();
505 1
        }
506
507
        if ($form instanceof FormInterface) {
508
            $form->setId($id);
0 ignored issues
show
It seems like $id can also be of type string; however, parameter $id of SleepingOwl\Admin\Contra...\FormInterface::setId() does only seem to accept integer, 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

508
            $form->setId(/** @scrutinizer ignore-type */ $id);
Loading history...
509
        }
510
511
        return $form;
512
    }
513 1
514
    /**
515 1
     * @param Closure|null $callback
516 1
     *
517
     * @return $this
518 1
     */
519
    public function onCreateAndEdit(Closure $callback = null)
520
    {
521
        $this->onCreate($callback);
522
        $this->onEdit($callback);
523
524 1
        return $this;
525
    }
526 1
527
    /**
528
     * @return Closure|null
529
     */
530
    public function getDelete()
531
    {
532
        return $this->delete;
533
    }
534 1
535
    /**
536 1
     * @param Closure|null $callback
537
     *
538 1
     * @return $this
539
     */
540
    public function onDelete(Closure $callback = null)
541
    {
542
        $this->delete = $callback;
543
544
        return $this;
545
    }
546 1
547
    /**
548 1
     * @param int|string $id
549 1
     *
550
     * @return mixed
551
     */
552
    public function fireDelete($id)
553
    {
554
        if (is_callable($this->getDelete())) {
555
            return $this->app->call($this->getDelete(), [$id]);
556 1
        }
557
    }
558 1
559
    /**
560
     * @return Closure|null
561
     */
562
    public function getDestroy()
563
    {
564
        return $this->destroy;
565
    }
566 1
567
    /**
568 1
     * @param Closure|null $callback
569
     *
570 1
     * @return $this
571
     */
572
    public function onDestroy(Closure $callback = null)
573
    {
574
        $this->destroy = $callback;
575
576
        return $this;
577
    }
578 1
579
    /**
580 1
     * @param int|string $id
581 1
     *
582
     * @return mixed
583
     */
584
    public function fireDestroy($id)
585
    {
586
        if (is_callable($this->getDestroy())) {
587
            return $this->app->call($this->getDestroy(), [$id]);
588 1
        }
589
    }
590 1
591
    /**
592
     * @return Closure|null
593
     */
594
    public function getRestore()
595
    {
596
        return $this->restore;
597
    }
598 1
599
    /**
600 1
     * @param Closure|null $callback
601
     *
602 1
     * @return $this
603
     */
604
    public function onRestore(Closure $callback = null)
605
    {
606
        $this->restore = $callback;
607
608
        return $this;
609
    }
610 1
611
    /**
612 1
     * @param int|string $id
613 1
     *
614
     * @return bool|mixed
615
     */
616
    public function fireRestore($id)
617
    {
618
        if (is_callable($this->getRestore())) {
619
            return $this->app->call($this->getRestore(), [$id]);
620 1
        }
621
    }
622 1
623 1
    /**
624 1
     * @return string
625
     */
626 1
    public function getMessageOnCreate()
627
    {
628
        if (is_null($this->messageOnCreate)) {
0 ignored issues
show
The condition is_null($this->messageOnCreate) is always false.
Loading history...
629
            $this->messageOnCreate = parent::getMessageOnCreate();
630
        }
631
632
        return $this->messageOnCreate;
633
    }
634 1
635
    /**
636 1
     * @param string $messageOnCreate
637
     *
638 1
     * @return $this
639
     */
640
    public function setMessageOnCreate($messageOnCreate)
641
    {
642
        $this->messageOnCreate = $messageOnCreate;
643
644 1
        return $this;
645
    }
646 1
647 1
    /**
648 1
     * @return string
649
     */
650 1
    public function getMessageOnUpdate()
651
    {
652
        if (is_null($this->messageOnUpdate)) {
0 ignored issues
show
The condition is_null($this->messageOnUpdate) is always false.
Loading history...
653
            $this->messageOnUpdate = parent::getMessageOnUpdate();
654
        }
655
656
        return $this->messageOnUpdate;
657
    }
658 1
659
    /**
660 1
     * @param string $messageOnUpdate
661
     *
662 1
     * @return $this
663
     */
664
    public function setMessageOnUpdate($messageOnUpdate)
665
    {
666
        $this->messageOnUpdate = $messageOnUpdate;
667
668 1
        return $this;
669
    }
670 1
671 1
    /**
672 1
     * @return string
673
     */
674 1
    public function getMessageOnDelete()
675
    {
676
        if (is_null($this->messageOnDelete)) {
0 ignored issues
show
The condition is_null($this->messageOnDelete) is always false.
Loading history...
677
            $this->messageOnDelete = parent::getMessageOnDelete();
678
        }
679
680
        return $this->messageOnDelete;
681
    }
682 1
683
    /**
684 1
     * @param string $messageOnDelete
685
     *
686 1
     * @return $this
687
     */
688
    public function setMessageOnDelete($messageOnDelete)
689
    {
690
        $this->messageOnDelete = $messageOnDelete;
691
692 1
        return $this;
693
    }
694 1
695 1
    /**
696 1
     * @return string
697
     */
698 1
    public function getMessageOnDestroy()
699
    {
700
        if (is_null($this->messageOnDestroy)) {
0 ignored issues
show
The condition is_null($this->messageOnDestroy) is always false.
Loading history...
701
            $this->messageOnDestroy = parent::getMessageOnDestroy();
702
        }
703
704
        return $this->messageOnDestroy;
705
    }
706 1
707
    /**
708 1
     * @param string $messageOnDestroy
709
     *
710 1
     * @return $this
711
     */
712
    public function setMessageOnDestroy($messageOnDestroy)
713
    {
714
        $this->messageOnDestroy = $messageOnDestroy;
715
716 1
        return $this;
717
    }
718 1
719 1
    /**
720 1
     * @return string
721
     */
722 1
    public function getMessageOnRestore()
723
    {
724
        if (is_null($this->messageOnRestore)) {
0 ignored issues
show
The condition is_null($this->messageOnRestore) is always false.
Loading history...
725
            $this->messageOnRestore = parent::getMessageOnRestore();
726
        }
727
728
        return $this->messageOnRestore;
729
    }
730 1
731
    /**
732 1
     * @param string $messageOnRestore
733
     *
734 1
     * @return $this
735
     */
736
    public function setMessageOnRestore($messageOnRestore)
737
    {
738
        $this->messageOnRestore = $messageOnRestore;
739
740
        return $this;
741
    }
742
}
743