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 ( 7dc89d...637663 )
by butschster
13s
created

ModelConfiguration::isDeletable()   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 SleepingOwl\Admin\Model;
4
5
use Closure;
6
use Illuminate\Database\Eloquent\Model;
7
use SleepingOwl\Admin\Contracts\DisplayInterface;
8
use SleepingOwl\Admin\Contracts\FormInterface;
9
use SleepingOwl\Admin\Contracts\Initializable;
10
11
class ModelConfiguration extends ModelConfigurationManager
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $createTitle;
17
18
    /**
19
     * @var string
20
     */
21
    protected $editTitle;
22
23
    /**
24
     * @var Closure|null
25
     */
26
    protected $display;
27
28
    /**
29
     * @var Closure|null
30
     */
31
    protected $create;
32
33
    /**
34
     * @var bool
35
     */
36
    protected $displayable = true;
37
38
    /**
39
     * @var bool
40
     */
41
    protected $creatable = true;
42
43
    /**
44
     * @var bool
45
     */
46
    protected $editable = true;
47
48
    /**
49
     * @var bool
50
     */
51
    protected $restorable = true;
52
53
    /**
54
     * @var bool
55
     */
56
    protected $deletable = true;
57
58
    /**
59
     * @var bool
60
     */
61
    protected $destroyable = true;
62
63
    /**
64
     * @var Closure|null
65
     */
66
    protected $edit;
67
68
    /**
69
     * @var Closure|null
70
     */
71
    protected $delete = true;
72
73
    /**
74
     * @var Closure|null
75
     */
76
    protected $destroy = true;
77
78
    /**
79
     * @var Closure|null
80
     */
81
    protected $restore = true;
82
83
    /**
84
     * @var string
85
     */
86
    protected $messageOnCreate;
87
88
    /**
89
     * @var string
90
     */
91
    protected $messageOnUpdate;
92
93
    /**
94
     * @var string
95
     */
96
    protected $messageOnDelete;
97
98
    /**
99
     * @var string
100
     */
101
    protected $messageOnDestroy;
102
103
    /**
104
     * @var string
105
     */
106
    protected $messageOnRestore;
107
108
    /**
109
     * @param string $alias
110
     *
111
     * @return $this
112
     */
113
    public function setAlias($alias)
114
    {
115
        $this->alias = $alias;
116
117
        return $this;
118
    }
119
120
    /**
121
     * @param string $title
122
     *
123
     * @return $this
124
     */
125
    public function setTitle($title)
126
    {
127
        $this->title = $title;
128
129
        return $this;
130
    }
131
132
    /**
133
     * @param bool $deletable
134
     *
135
     * @return $this
136
     */
137
    public function setDeletable($deletable)
138
    {
139
        $this->deletable = $deletable;
140
141
        return $this;
142
    }
143
144
    /**
145
     * @return string|\Symfony\Component\Translation\TranslatorInterface
146
     */
147
    public function getCreateTitle()
148
    {
149
        if (is_null($this->createTitle)) {
150
            return parent::getCreateTitle();
151
        }
152
153
        return $this->createTitle;
154
    }
155
156
    /**
157
     * @param string $title
158
     *
159
     * @return $this
160
     */
161
    public function setCreateTitle($title)
162
    {
163
        $this->createTitle = $title;
164
165
        return $this;
166
    }
167
168
    /**
169
     * @return string|\Symfony\Component\Translation\TranslatorInterface
170
     */
171
    public function getEditTitle()
172
    {
173
        if (is_null($this->editTitle)) {
174
            return parent::getEditTitle();
175
        }
176
177
        return $this->editTitle;
178
    }
179
180
    /**
181
     * @param string $title
182
     *
183
     * @return $this
184
     */
185
    public function setEditTitle($title)
186
    {
187
        $this->editTitle = $title;
188
189
        return $this;
190
    }
191
192
    /**
193
     * @return Closure|null
194
     */
195
    public function getRestore()
196
    {
197
        return $this->restore;
198
    }
199
200
    /**
201
     * @return Closure|null
202
     */
203
    public function getDelete()
204
    {
205
        return $this->delete;
206
    }
207
208
    /**
209
     * @return Closure|null
210
     */
211
    public function getDestroy()
212
    {
213
        return $this->destroy;
214
    }
215
216
    /**
217
     * @return Closure|null
218
     */
219
    public function getEdit()
220
    {
221
        return $this->edit;
222
    }
223
224
    /**
225
     * @return Closure|null
226
     */
227
    public function getCreate()
228
    {
229
        return $this->create;
230
    }
231
232
    /**
233
     * @return Closure|null
234
     */
235
    public function getDisplay()
236
    {
237
        return $this->display;
238
    }
239
240
    /**
241
     * @param Closure|null $callback
242
     *
243
     * @return $this
244
     */
245
    public function onCreate(Closure $callback = null)
246
    {
247
        $this->create = $callback;
248
249
        return $this;
250
    }
251
252
    /**
253
     * @param Closure|null $callback
254
     *
255
     * @return $this
256
     */
257
    public function onEdit(Closure $callback = null)
258
    {
259
        $this->edit = $callback;
260
261
        return $this;
262
    }
263
264
    /**
265
     * @param Closure|null $callback
266
     *
267
     * @return $this
268
     */
269
    public function onCreateAndEdit(Closure $callback = null)
270
    {
271
        $this->onCreate($callback);
272
        $this->onEdit($callback);
273
274
        return $this;
275
    }
276
277
    /**
278
     * @param Closure|null $callback
279
     *
280
     * @return $this
281
     */
282
    public function onDelete(Closure $callback = null)
283
    {
284
        $this->delete = $callback;
285
286
        return $this;
287
    }
288
289
    /**
290
     * @param Closure|null $callback
291
     *
292
     * @return $this
293
     */
294
    public function onDestroy(Closure $callback = null)
295
    {
296
        $this->destroy = $callback;
297
298
        return $this;
299
    }
300
301
    /**
302
     * @param Closure|null $callback
303
     *
304
     * @return $this
305
     */
306
    public function onRestore(Closure $callback = null)
307
    {
308
        $this->restore = $callback;
309
310
        return $this;
311
    }
312
313
    /**
314
     * @param Closure $callback
315
     *
316
     * @return $this
317
     */
318
    public function onDisplay(Closure $callback)
319
    {
320
        $this->display = $callback;
321
322
        return $this;
323
    }
324
325
    /**
326
     * @return bool
327
     */
328
    public function isDisplayable()
329
    {
330
        return $this->displayable && parent::isDisplayable();
331
    }
332
333
    /**
334
     * @return $this
335
     */
336
    public function disableDisplay()
337
    {
338
        $this->displayable = false;
339
340
        return $this;
341
    }
342
343
    /**
344
     * @return bool
345
     */
346
    public function isCreatable()
347
    {
348
        if (! is_callable($this->getCreate())) {
349
            return false;
350
        }
351
352
        return $this->creatable && parent::isCreatable($this->getModel());
0 ignored issues
show
Unused Code introduced by
The call to ModelConfigurationManager::isCreatable() has too many arguments starting with $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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
353
    }
354
355
    /**
356
     * @return $this
357
     */
358
    public function disableCreating()
359
    {
360
        $this->creatable = false;
361
362
        return $this;
363
    }
364
365
    /**
366
     * @param Model $model
367
     *
368
     * @return bool
369
     */
370
    public function isEditable(Model $model)
371
    {
372
        if (! is_callable($this->getEdit())) {
373
            return false;
374
        }
375
376
        return $this->editable && parent::isEditable($model);
377
    }
378
379
    /**
380
     * @return $this
381
     */
382
    public function disableEditing()
383
    {
384
        $this->editable = false;
385
386
        return $this;
387
    }
388
389
    /**
390
     * @param Model $model
391
     *
392
     * @return bool
393
     */
394
    public function isDeletable(Model $model)
395
    {
396
        return $this->deletable && parent::isDeletable($model);
397
    }
398
399
    /**
400
     * @return $this
401
     */
402
    public function disableDeleting()
403
    {
404
        $this->deletable = false;
405
406
        return $this;
407
    }
408
409
    /**
410
     * @param Model $model
411
     *
412
     * @return bool
413
     */
414
    public function isDestroyable(Model $model)
415
    {
416
        return $this->destroyable && parent::isDestroyable($model);
417
    }
418
419
    /**
420
     * @return $this
421
     */
422
    public function disableDestroying()
423
    {
424
        $this->destroyable = false;
425
426
        return $this;
427
    }
428
429
    /**
430
     * @param Model $model
431
     *
432
     * @return bool
433
     */
434
    public function isRestorable(Model $model)
435
    {
436
        return $this->restorable && parent::isRestorable($model);
437
    }
438
439
    /**
440
     * @return bool
441
     */
442
    public function isRestorableModel()
443
    {
444
        return $this->restorable && parent::isRestorableModel();
445
    }
446
447
    /**
448
     * @return $this
449
     */
450
    public function disableRestoring()
451
    {
452
        $this->restorable = false;
453
454
        return $this;
455
    }
456
457
    /**
458
     * @return $this
459
     */
460
    public function enableAccessCheck()
461
    {
462
        $this->checkAccess = true;
463
464
        return $this;
465
    }
466
467
    /**
468
     * @return $this
469
     */
470
    public function disableAccessCheck()
471
    {
472
        $this->checkAccess = false;
473
474
        return $this;
475
    }
476
477
    /**
478
     * @return DisplayInterface|mixed
479
     */
480
    public function fireDisplay()
481
    {
482
        if (! is_callable($this->display)) {
483
            return;
484
        }
485
486
        $display = app()->call($this->display);
487
        if ($display instanceof DisplayInterface) {
488
            $display->setModelClass($this->getClass());
489
            $display->initialize();
490
        }
491
492
        return $display;
493
    }
494
495
    /**
496
     * @return mixed|void
497
     */
498
    public function fireCreate()
499
    {
500
        if (! is_callable($this->create)) {
501
            return;
502
        }
503
504
        $form = app()->call($this->create);
505
        if ($form instanceof DisplayInterface) {
506
            $form->setModelClass($this->getClass());
507
        }
508
509
        if ($form instanceof Initializable) {
510
            $form->initialize();
511
        }
512
513
        if ($form instanceof FormInterface) {
514
            $form->setAction($this->getStoreUrl());
515
        }
516
517
        return $form;
518
    }
519
520
    /**
521
     * @param $id
522
     *
523
     * @return mixed|void
524
     */
525
    public function fireEdit($id)
526
    {
527
        if (! is_callable($this->edit)) {
528
            return;
529
        }
530
531
        $form = app()->call($this->edit, ['id' => $id]);
532
        if ($form instanceof DisplayInterface) {
533
            $form->setModelClass($this->getClass());
534
        }
535
536
        if ($form instanceof Initializable) {
537
            $form->initialize();
538
        }
539
540
        if ($form instanceof FormInterface) {
541
            $form->setAction($this->getUpdateUrl($id));
542
            $form->setId($id);
543
        }
544
545
        return $form;
546
    }
547
548
    /**
549
     * @param $id
550
     *
551
     * @return mixed
552
     */
553
    public function fireDelete($id)
554
    {
555
        if (is_callable($this->getDelete())) {
556
            return app()->call($this->getDelete(), [$id]);
557
        }
558
    }
559
560
    /**
561
     * @param $id
562
     *
563
     * @return mixed
564
     */
565
    public function fireDestroy($id)
566
    {
567
        if (is_callable($this->getDestroy())) {
568
            return app()->call($this->getDestroy(), [$id]);
569
        }
570
    }
571
572
    /**
573
     * @param $id
574
     *
575
     * @return bool|mixed
576
     */
577
    public function fireRestore($id)
578
    {
579
        if (is_callable($this->getRestore())) {
580
            return app()->call($this->getRestore(), [$id]);
581
        }
582
583
        return $this->getRestore();
584
    }
585
586
    /**
587
     * @return string
588
     */
589
    public function getMessageOnCreate()
590
    {
591
        if (is_null($this->messageOnUpdate)) {
592
            $this->messageOnUpdate = parent::getMessageOnCreate();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnCreate() can also be of type object<Symfony\Component...on\TranslatorInterface>. However, the property $messageOnUpdate is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
593
        }
594
595
        return $this->messageOnCreate;
596
    }
597
598
    /**
599
     * @param string $messageOnCreate
600
     */
601
    public function setMessageOnCreate($messageOnCreate)
602
    {
603
        $this->messageOnCreate = $messageOnCreate;
604
    }
605
606
    /**
607
     * @return string
608
     */
609
    public function getMessageOnUpdate()
610
    {
611
        if (is_null($this->messageOnUpdate)) {
612
            $this->messageOnUpdate = parent::getMessageOnUpdate();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnUpdate() can also be of type object<Symfony\Component...on\TranslatorInterface>. However, the property $messageOnUpdate is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
613
        }
614
615
        return $this->messageOnUpdate;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnUpdate; of type Symfony\Component\Transl...nslatorInterface|string adds the type Symfony\Component\Translation\TranslatorInterface to the return on line 615 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ace::getMessageOnUpdate of type string.
Loading history...
616
    }
617
618
    /**
619
     * @param string $messageOnUpdate
620
     *
621
     * @return $this
622
     */
623
    public function setMessageOnUpdate($messageOnUpdate)
624
    {
625
        $this->messageOnUpdate = $messageOnUpdate;
626
627
        return $this;
628
    }
629
630
    /**
631
     * @return string
632
     */
633
    public function getMessageOnDelete()
634
    {
635
        if (is_null($this->messageOnDelete)) {
636
            $this->messageOnDelete = parent::getMessageOnDelete();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnDelete() can also be of type object<Symfony\Component...on\TranslatorInterface>. However, the property $messageOnDelete is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
637
        }
638
639
        return $this->messageOnDelete;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnDelete; of type Symfony\Component\Transl...nslatorInterface|string adds the type Symfony\Component\Translation\TranslatorInterface to the return on line 639 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ace::getMessageOnDelete of type string.
Loading history...
640
    }
641
642
    /**
643
     * @return string
644
     */
645
    public function getMessageOnDestroy()
646
    {
647
        if (is_null($this->messageOnDestroy)) {
648
            $this->messageOnDestroy = parent::getMessageOnDestroy();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnDestroy() can also be of type object<Symfony\Component...on\TranslatorInterface>. However, the property $messageOnDestroy is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
649
        }
650
651
        return $this->messageOnDestroy;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnDestroy; of type Symfony\Component\Transl...nslatorInterface|string adds the type Symfony\Component\Translation\TranslatorInterface to the return on line 651 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ce::getMessageOnDestroy of type string.
Loading history...
652
    }
653
654
    /**
655
     * @param string $messageOnDelete
656
     *
657
     * @return $this
658
     */
659
    public function setMessageOnDelete($messageOnDelete)
660
    {
661
        $this->messageOnDelete = $messageOnDelete;
662
663
        return $this;
664
    }
665
666
    /**
667
     * @param string $messageOnDestroy
668
     *
669
     * @return $this
670
     */
671
    public function setMessageOnDestroy($messageOnDestroy)
672
    {
673
        $this->messageOnDestroy = $messageOnDestroy;
674
675
        return $this;
676
    }
677
678
    /**
679
     * @return string
680
     */
681
    public function getMessageOnRestore()
682
    {
683
        if (is_null($this->messageOnRestore)) {
684
            $this->messageOnRestore = parent::getMessageOnRestore();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnRestore() can also be of type object<Symfony\Component...on\TranslatorInterface>. However, the property $messageOnRestore is declared as type string. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
685
        }
686
687
        return $this->messageOnRestore;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnRestore; of type Symfony\Component\Transl...nslatorInterface|string adds the type Symfony\Component\Translation\TranslatorInterface to the return on line 687 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ce::getMessageOnRestore of type string.
Loading history...
688
    }
689
690
    /**
691
     * @param string $messageOnRestore
692
     *
693
     * @return $this
694
     */
695
    public function setMessageOnRestore($messageOnRestore)
696
    {
697
        $this->messageOnRestore = $messageOnRestore;
698
699
        return $this;
700
    }
701
702
    /**
703
     * @param string $controllerClass
704
     *
705
     * @return $this
706
     */
707
    public function setControllerClass($controllerClass)
708
    {
709
        $this->controllerClass = $controllerClass;
710
711
        return $this;
712
    }
713
}
714