| Conditions | 7 |
| Paths | 6 |
| Total Lines | 35 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | public function turn(string $direction, string $id): void |
||
| 28 | { |
||
| 29 | if (!Any::isInt($id) || $id < 1) { |
||
| 30 | throw new NotFoundException('Bad is format'); |
||
| 31 | } |
||
| 32 | // try to find record |
||
| 33 | $record = FeedbackPost::find($id); |
||
| 34 | if (!$record) { |
||
| 35 | throw new NotFoundException(__('Feedback request with id %id% is not found', ['id' => $id])); |
||
| 36 | } |
||
| 37 | |||
| 38 | // switch operation direction to what we must change |
||
| 39 | switch ($direction) { |
||
| 40 | case 'open': |
||
| 41 | $record->closed = 0; |
||
|
|
|||
| 42 | $record->save(); |
||
| 43 | break; |
||
| 44 | case 'close': |
||
| 45 | $record->closed = 1; |
||
| 46 | $record->save(); |
||
| 47 | break; |
||
| 48 | case 'read': |
||
| 49 | $record->readed = 1; |
||
| 50 | $record->save(); |
||
| 51 | break; |
||
| 52 | default: |
||
| 53 | throw new NotFoundException(__('Hack attention')); |
||
| 54 | break; |
||
| 55 | } |
||
| 56 | |||
| 57 | // add notification of successful changes |
||
| 58 | App::$Session->getFlashBag()->add('success', __('Feedback request is changed!')); |
||
| 59 | |||
| 60 | // redirect to feedback post read |
||
| 61 | $this->response->redirect('feedback/read/' . $id); |
||
| 62 | } |
||
| 64 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.