Conditions | 7 |
Paths | 6 |
Total Lines | 36 |
Code Lines | 24 |
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 | } |
||
63 | } |
||
64 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.