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.
Passed
Push — master ( b2510c...ee0bb8 )
by
unknown
12:46
created

ModelConfiguration   F

Complexity

Total Complexity 83

Size/Duplication

Total Lines 700
Duplicated Lines 6.14 %

Coupling/Cohesion

Components 13
Dependencies 6

Test Coverage

Coverage 95.36%

Importance

Changes 0
Metric Value
dl 43
loc 700
c 0
b 0
f 0
ccs 185
cts 194
cp 0.9536
rs 1.263
wmc 83
lcom 13
cbo 6

50 Methods

Rating   Name   Duplication   Size   Complexity  
A setAlias() 0 6 1
A setTitle() 0 6 1
A getCreateTitle() 0 8 2
A setCreateTitle() 0 6 1
A getEditTitle() 0 8 2
A setEditTitle() 0 6 1
A isDisplayable() 0 4 2
A disableDisplay() 0 6 1
A can() 0 8 2
A isCreatable() 0 8 3
A disableCreating() 0 6 1
A isEditable() 0 8 3
A disableEditing() 0 6 1
A setDeletable() 0 6 1
A isDeletable() 0 4 2
A disableDeleting() 0 6 1
A isDestroyable() 0 4 2
A disableDestroying() 0 6 1
A isRestorable() 0 4 2
A isRestorableModel() 0 4 2
A disableRestoring() 0 6 1
A getDisplay() 0 4 1
A onDisplay() 0 6 1
B fireDisplay() 22 22 5
A getCreate() 0 4 1
A onCreate() 0 6 1
B fireCreate() 21 21 5
A getEdit() 0 4 1
A onEdit() 0 6 1
B fireEdit() 0 25 6
A onCreateAndEdit() 0 7 1
A getDelete() 0 4 1
A onDelete() 0 6 1
A fireDelete() 0 6 2
A getDestroy() 0 4 1
A onDestroy() 0 6 1
A fireDestroy() 0 6 2
A getRestore() 0 4 1
A onRestore() 0 6 1
A fireRestore() 0 6 2
A getMessageOnCreate() 0 8 2
A setMessageOnCreate() 0 6 1
A getMessageOnUpdate() 0 8 2
A setMessageOnUpdate() 0 6 1
A getMessageOnDelete() 0 8 2
A setMessageOnDelete() 0 6 1
A getMessageOnDestroy() 0 8 2
A setMessageOnDestroy() 0 6 1
A getMessageOnRestore() 0 8 2
A setMessageOnRestore() 0 6 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ModelConfiguration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ModelConfiguration, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace SleepingOwl\Admin\Model;
4
5
use Closure;
6
use Illuminate\Database\Eloquent\Model;
7
use SleepingOwl\Admin\Contracts\Initializable;
8
use SleepingOwl\Admin\Contracts\Form\FormInterface;
9
use SleepingOwl\Admin\Display\DisplayDatatablesAsync;
10
use SleepingOwl\Admin\Contracts\Display\DisplayInterface;
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
    /**
110
     * @param string $alias
111
     *
112
     * @return $this
113
     */
114 1
    public function setAlias($alias)
115
    {
116 1
        $this->alias = $alias;
117
118 1
        return $this;
119
    }
120
121
    /**
122
     * @param string $title
123
     *
124
     * @return $this
125
     */
126 1
    public function setTitle($title)
127
    {
128 1
        $this->title = $title;
129
130 1
        return $this;
131
    }
132
133
    /**
134
     * @return string|\Symfony\Component\Translation\TranslatorInterface
135
     */
136 1
    public function getCreateTitle()
137
    {
138 1
        if (is_null($this->createTitle)) {
139 1
            return parent::getCreateTitle();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::getCreateTitle(); of type Illuminate\Contracts\Translation\Translator|string adds the type Illuminate\Contracts\Translation\Translator to the return on line 139 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...terface::getCreateTitle of type string|Symfony\Component...ion\TranslatorInterface.
Loading history...
140
        }
141
142 1
        return $this->createTitle;
143
    }
144
145
    /**
146
     * @param string $title
147
     *
148
     * @return $this
149
     */
150 1
    public function setCreateTitle($title)
151
    {
152 1
        $this->createTitle = $title;
153
154 1
        return $this;
155
    }
156
157
    /**
158
     * @return string|\Symfony\Component\Translation\TranslatorInterface
159
     */
160 1
    public function getEditTitle()
161
    {
162 1
        if (is_null($this->editTitle)) {
163 1
            return parent::getEditTitle();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::getEditTitle(); of type Illuminate\Contracts\Translation\Translator|string adds the type Illuminate\Contracts\Translation\Translator to the return on line 163 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...Interface::getEditTitle of type string|Symfony\Component...ion\TranslatorInterface.
Loading history...
164
        }
165
166 1
        return $this->editTitle;
167
    }
168
169
    /**
170
     * @param string $title
171
     *
172
     * @return $this
173
     */
174 1
    public function setEditTitle($title)
175
    {
176 1
        $this->editTitle = $title;
177
178 1
        return $this;
179
    }
180
181
    /**
182
     * @return bool
183
     */
184 1
    public function isDisplayable()
185
    {
186 1
        return $this->displayable && parent::isDisplayable();
187
    }
188
189
    /**
190
     * @return $this
191
     */
192 1
    public function disableDisplay()
193
    {
194 1
        $this->displayable = false;
195
196 1
        return $this;
197
    }
198
199
    /**
200
     * @param string $action
201
     * @param \Illuminate\Database\Eloquent\Model $model
202
     *
203
     * @return bool
204
     */
205 6
    public function can($action, Model $model)
206
    {
207 6
        if (! $this->checkAccess) {
208 6
            return true;
209
        }
210
211
        return \Gate::allows($action, $model);
212
    }
213
214
    /**
215
     * @return bool
216
     */
217 1
    public function isCreatable()
218
    {
219 1
        if (! is_callable($this->getCreate())) {
220 1
            return false;
221
        }
222
223 1
        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...
224
    }
225
226
    /**
227
     * @return $this
228
     */
229 1
    public function disableCreating()
230
    {
231 1
        $this->creatable = false;
232
233 1
        return $this;
234
    }
235
236
    /**
237
     * @param Model $model
238
     *
239
     * @return bool
240
     */
241 1
    public function isEditable(Model $model)
242
    {
243 1
        if (! is_callable($this->getEdit())) {
244 1
            return false;
245
        }
246
247 1
        return $this->editable && parent::isEditable($model);
248
    }
249
250
    /**
251
     * @return $this
252
     */
253 1
    public function disableEditing()
254
    {
255 1
        $this->editable = false;
256
257 1
        return $this;
258
    }
259
260
    /**
261
     * @param bool $deletable
262
     *
263
     * @return $this
264
     */
265 1
    public function setDeletable($deletable)
266
    {
267 1
        $this->deletable = (bool) $deletable;
268
269 1
        return $this;
270
    }
271
272
    /**
273
     * @param Model $model
274
     *
275
     * @return bool
276
     */
277 1
    public function isDeletable(Model $model)
278
    {
279 1
        return $this->deletable && parent::isDeletable($model);
280
    }
281
282
    /**
283
     * @return $this
284
     */
285 1
    public function disableDeleting()
286
    {
287 1
        $this->setDeletable(false);
288
289 1
        return $this;
290
    }
291
292
    /**
293
     * @param Model $model
294
     *
295
     * @return bool
296
     */
297 3
    public function isDestroyable(Model $model)
298
    {
299 3
        return $this->destroyable && parent::isDestroyable($model);
300
    }
301
302
    /**
303
     * @return $this
304
     */
305 1
    public function disableDestroying()
306
    {
307 1
        $this->destroyable = false;
308
309 1
        return $this;
310
    }
311
312
    /**
313
     * @param Model $model
314
     *
315
     * @return bool
316
     */
317 1
    public function isRestorable(Model $model)
318
    {
319 1
        return $this->restorable && parent::isRestorable($model);
320
    }
321
322
    /**
323
     * @return bool
324
     */
325 6
    public function isRestorableModel()
326
    {
327 6
        return $this->restorable && parent::isRestorableModel();
328
    }
329
330
    /**
331
     * @return $this
332
     */
333 1
    public function disableRestoring()
334
    {
335 1
        $this->restorable = false;
336
337 1
        return $this;
338
    }
339
340
    /**
341
     * @return Closure|null
342
     */
343 1
    public function getDisplay()
344
    {
345 1
        return $this->display;
346
    }
347
348
    /**
349
     * @param Closure $callback
350
     *
351
     * @return $this
352
     */
353 1
    public function onDisplay(Closure $callback)
354
    {
355 1
        $this->display = $callback;
356
357 1
        return $this;
358
    }
359
360
    /**
361
     * @param array|null $payload
362
     * @return DisplayInterface|mixed
363
     */
364 1 View Code Duplication
    public function fireDisplay(array $payload = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
365
    {
366 1
        if (! is_callable($this->getDisplay())) {
367
            return;
368
        }
369
370 1
        $display = $this->app->call($this->getDisplay(), $payload);
371
372 1
        if ($display instanceof DisplayDatatablesAsync) {
373
            $display->setPayload($payload);
374
        }
375
376 1
        if ($display instanceof DisplayInterface) {
377 1
            $display->setModelClass($this->getClass());
378 1
        }
379
380 1
        if ($display instanceof Initializable) {
381 1
            $display->initialize();
382 1
        }
383
384 1
        return $display;
385
    }
386
387
    /**
388
     * @return Closure|null
389
     */
390 3
    public function getCreate()
391
    {
392 3
        return $this->create;
393
    }
394
395
    /**
396
     * @param Closure|null $callback
397
     *
398
     * @return $this
399
     */
400 3
    public function onCreate(Closure $callback = null)
401
    {
402 3
        $this->create = $callback;
403
404 3
        return $this;
405
    }
406
407
    /**
408
     * @return mixed|void
409
     */
410 1 View Code Duplication
    public function fireCreate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
411
    {
412 1
        if (! is_callable($this->getCreate())) {
413
            return;
414
        }
415
416 1
        $form = $this->app->call($this->getCreate());
417 1
        if ($form instanceof DisplayInterface) {
418 1
            $form->setModelClass($this->getClass());
419 1
        }
420
421 1
        if ($form instanceof FormInterface) {
422 1
            $form->setAction($this->getStoreUrl());
423 1
        }
424
425 1
        if ($form instanceof Initializable) {
426 1
            $form->initialize();
427 1
        }
428
429 1
        return $form;
430
    }
431
432
    /**
433
     * @return Closure|null
434
     */
435 3
    public function getEdit()
436
    {
437 3
        return $this->edit;
438
    }
439
440
    /**
441
     * @param Closure|null $callback
442
     *
443
     * @return $this
444
     */
445 3
    public function onEdit(Closure $callback = null)
446
    {
447 3
        $this->edit = $callback;
448
449 3
        return $this;
450
    }
451
452
    /**
453
     * @param int|string $id
454
     *
455
     * @return mixed|void
456
     */
457 1
    public function fireEdit($id)
458
    {
459 1
        if (! is_callable($this->getEdit())) {
460
            return;
461
        }
462
463 1
        $form = $this->app->call($this->getEdit(), ['id' => $id]);
464 1
        if ($form instanceof DisplayInterface) {
465 1
            $form->setModelClass($this->getClass());
466 1
        }
467
468 1
        if ($form instanceof FormInterface) {
469 1
            $form->setAction($this->getUpdateUrl($id));
470 1
        }
471
472 1
        if ($form instanceof Initializable) {
473 1
            $form->initialize();
474 1
        }
475
476 1
        if ($form instanceof FormInterface) {
477 1
            $form->setId($id);
478 1
        }
479
480 1
        return $form;
481
    }
482
483
    /**
484
     * @param Closure|null $callback
485
     *
486
     * @return $this
487
     */
488 1
    public function onCreateAndEdit(Closure $callback = null)
489
    {
490 1
        $this->onCreate($callback);
491 1
        $this->onEdit($callback);
492
493 1
        return $this;
494
    }
495
496
    /**
497
     * @return Closure|null
498
     */
499 1
    public function getDelete()
500
    {
501 1
        return $this->delete;
502
    }
503
504
    /**
505
     * @param Closure|null $callback
506
     *
507
     * @return $this
508
     */
509 1
    public function onDelete(Closure $callback = null)
510
    {
511 1
        $this->delete = $callback;
512
513 1
        return $this;
514
    }
515
516
    /**
517
     * @param int|string $id
518
     *
519
     * @return mixed
520
     */
521 1
    public function fireDelete($id)
522
    {
523 1
        if (is_callable($this->getDelete())) {
524 1
            return $this->app->call($this->getDelete(), [$id]);
525
        }
526
    }
527
528
    /**
529
     * @return Closure|null
530
     */
531 1
    public function getDestroy()
532
    {
533 1
        return $this->destroy;
534
    }
535
536
    /**
537
     * @param Closure|null $callback
538
     *
539
     * @return $this
540
     */
541 1
    public function onDestroy(Closure $callback = null)
542
    {
543 1
        $this->destroy = $callback;
544
545 1
        return $this;
546
    }
547
548
    /**
549
     * @param int|string $id
550
     *
551
     * @return mixed
552
     */
553 1
    public function fireDestroy($id)
554
    {
555 1
        if (is_callable($this->getDestroy())) {
556 1
            return $this->app->call($this->getDestroy(), [$id]);
557
        }
558
    }
559
560
    /**
561
     * @return Closure|null
562
     */
563 1
    public function getRestore()
564
    {
565 1
        return $this->restore;
566
    }
567
568
    /**
569
     * @param Closure|null $callback
570
     *
571
     * @return $this
572
     */
573 1
    public function onRestore(Closure $callback = null)
574
    {
575 1
        $this->restore = $callback;
576
577 1
        return $this;
578
    }
579
580
    /**
581
     * @param int|string $id
582
     *
583
     * @return bool|mixed
584
     */
585 1
    public function fireRestore($id)
586
    {
587 1
        if (is_callable($this->getRestore())) {
588 1
            return $this->app->call($this->getRestore(), [$id]);
589
        }
590
    }
591
592
    /**
593
     * @return string
594
     */
595 1
    public function getMessageOnCreate()
596
    {
597 1
        if (is_null($this->messageOnCreate)) {
598 1
            $this->messageOnCreate = parent::getMessageOnCreate();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnCreate() can also be of type object<Illuminate\Contra...Translation\Translator>. However, the property $messageOnCreate 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...
599 1
        }
600
601 1
        return $this->messageOnCreate;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnCreate; of type Illuminate\Contracts\Translation\Translator|string adds the type Illuminate\Contracts\Translation\Translator to the return on line 601 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ace::getMessageOnCreate of type string.
Loading history...
602
    }
603
604
    /**
605
     * @param string $messageOnCreate
606
     *
607
     * @return $this
608
     */
609 1
    public function setMessageOnCreate($messageOnCreate)
610
    {
611 1
        $this->messageOnCreate = $messageOnCreate;
612
613 1
        return $this;
614
    }
615
616
    /**
617
     * @return string
618
     */
619 1
    public function getMessageOnUpdate()
620
    {
621 1
        if (is_null($this->messageOnUpdate)) {
622 1
            $this->messageOnUpdate = parent::getMessageOnUpdate();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnUpdate() can also be of type object<Illuminate\Contra...Translation\Translator>. 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...
623 1
        }
624
625 1
        return $this->messageOnUpdate;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnUpdate; of type Illuminate\Contracts\Translation\Translator|string adds the type Illuminate\Contracts\Translation\Translator to the return on line 625 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ace::getMessageOnUpdate of type string.
Loading history...
626
    }
627
628
    /**
629
     * @param string $messageOnUpdate
630
     *
631
     * @return $this
632
     */
633 1
    public function setMessageOnUpdate($messageOnUpdate)
634
    {
635 1
        $this->messageOnUpdate = $messageOnUpdate;
636
637 1
        return $this;
638
    }
639
640
    /**
641
     * @return string
642
     */
643 1
    public function getMessageOnDelete()
644
    {
645 1
        if (is_null($this->messageOnDelete)) {
646 1
            $this->messageOnDelete = parent::getMessageOnDelete();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnDelete() can also be of type object<Illuminate\Contra...Translation\Translator>. 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...
647 1
        }
648
649 1
        return $this->messageOnDelete;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnDelete; of type Illuminate\Contracts\Translation\Translator|string adds the type Illuminate\Contracts\Translation\Translator to the return on line 649 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ace::getMessageOnDelete of type string.
Loading history...
650
    }
651
652
    /**
653
     * @param string $messageOnDelete
654
     *
655
     * @return $this
656
     */
657 1
    public function setMessageOnDelete($messageOnDelete)
658
    {
659 1
        $this->messageOnDelete = $messageOnDelete;
660
661 1
        return $this;
662
    }
663
664
    /**
665
     * @return string
666
     */
667 1
    public function getMessageOnDestroy()
668
    {
669 1
        if (is_null($this->messageOnDestroy)) {
670 1
            $this->messageOnDestroy = parent::getMessageOnDestroy();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnDestroy() can also be of type object<Illuminate\Contra...Translation\Translator>. 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...
671 1
        }
672
673 1
        return $this->messageOnDestroy;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnDestroy; of type Illuminate\Contracts\Translation\Translator|string adds the type Illuminate\Contracts\Translation\Translator to the return on line 673 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ce::getMessageOnDestroy of type string.
Loading history...
674
    }
675
676
    /**
677
     * @param string $messageOnDestroy
678
     *
679
     * @return $this
680
     */
681 1
    public function setMessageOnDestroy($messageOnDestroy)
682
    {
683 1
        $this->messageOnDestroy = $messageOnDestroy;
684
685 1
        return $this;
686
    }
687
688
    /**
689
     * @return string
690
     */
691 1
    public function getMessageOnRestore()
692
    {
693 1
        if (is_null($this->messageOnRestore)) {
694 1
            $this->messageOnRestore = parent::getMessageOnRestore();
0 ignored issues
show
Documentation Bug introduced by
It seems like parent::getMessageOnRestore() can also be of type object<Illuminate\Contra...Translation\Translator>. 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...
695 1
        }
696
697 1
        return $this->messageOnRestore;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->messageOnRestore; of type Illuminate\Contracts\Translation\Translator|string adds the type Illuminate\Contracts\Translation\Translator to the return on line 697 which is incompatible with the return type declared by the interface SleepingOwl\Admin\Contra...ce::getMessageOnRestore of type string.
Loading history...
698
    }
699
700
    /**
701
     * @param string $messageOnRestore
702
     *
703
     * @return $this
704
     */
705 1
    public function setMessageOnRestore($messageOnRestore)
706
    {
707 1
        $this->messageOnRestore = $messageOnRestore;
708
709 1
        return $this;
710
    }
711
}
712