| Conditions | 4 |
| Paths | 4 |
| Total Lines | 36 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 97 | public function restore() |
||
| 98 | { |
||
| 99 | if (!$this instanceof TrashInterface) |
||
| 100 | { |
||
| 101 | // When trying to restore normal document instead of trash item |
||
| 102 | throw new Exception('Restore can be performed only on `%s` instance', TrashInterface::class); |
||
| 103 | } |
||
| 104 | $em = new EntityManager($this->data); |
||
|
1 ignored issue
–
show
|
|||
| 105 | |||
| 106 | Event::trigger($this->data, TrashInterface::EventBeforeRestore); |
||
|
1 ignored issue
–
show
|
|||
| 107 | |||
| 108 | $saved = $em->save(); |
||
| 109 | if (!$saved) |
||
| 110 | { |
||
| 111 | return false; |
||
| 112 | } |
||
| 113 | $finder = new Finder($this->data); |
||
|
1 ignored issue
–
show
|
|||
| 114 | $model = $finder->find(PkManager::prepareFromModel($this->data)); |
||
|
1 ignored issue
–
show
|
|||
| 115 | if (!$model) |
||
| 116 | { |
||
| 117 | return false; |
||
| 118 | } |
||
| 119 | $eventAfter = new RestoreEvent(); |
||
| 120 | $eventAfter->setTrashed($this); |
||
| 121 | Event::trigger($model, TrashInterface::EventAfterRestore, $eventAfter); |
||
| 122 | |||
| 123 | $trashEm = new EntityManager($this); |
||
| 124 | |||
| 125 | // Use deleteOne, to avoid beforeDelete event, |
||
| 126 | // which should be raised only when really removing document: |
||
| 127 | // when emtying trash |
||
| 128 | $this->data = null; |
||
|
1 ignored issue
–
show
|
|||
| 129 | |||
| 130 | $trashEm->deleteOne(PkManager::prepareFromModel($this)); |
||
| 131 | return true; |
||
| 132 | } |
||
| 133 | |||
| 135 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: