for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Apps\Controller\Admin\Feedback;
use Apps\ActiveRecord\FeedbackPost;
use Ffcms\Core\App;
use Ffcms\Core\Exception\NotFoundException;
use Ffcms\Core\Helper\Type\Any;
use Ffcms\Core\Network\Request;
use Ffcms\Core\Network\Response;
/**
* Trait ActionTurn
* @package Apps\Controller\Admin\Feedback
* @property Request $request
* @property Response $response
*/
trait ActionTurn
{
* Turn feedback request post - close, open, readed
* @param string $direction
* @param string $id
* @return void
* @throws NotFoundException
public function turn(string $direction, string $id): void
if (!Any::isInt($id) || $id < 1) {
throw new NotFoundException('Bad is format');
}
// try to find record
$record = FeedbackPost::find($id);
if (!$record) {
throw new NotFoundException(__('Feedback request with id %id% is not found', ['id' => $id]));
// switch operation direction to what we must change
switch ($direction) {
case 'open':
$record->closed = 0;
$record->save();
break;
case 'close':
$record->closed = 1;
case 'read':
$record->readed = 1;
default:
throw new NotFoundException(__('Hack attention'));
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 or exit statements that have been added for debug purposes.
return
die
exit
function fx() { try { doSomething(); return true; } catch (\Exception $e) { return false; } return false; }
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.
return false
// add notification of successful changes
App::$Session->getFlashBag()->add('success', __('Feedback request is changed!'));
// redirect to feedback post read
$this->response->redirect('feedback/read/' . $id);
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.