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;
$closed
boolean
0
integer
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.
$answer = 42; $correct = false; $correct = (bool) $answer;
$record->save();
break;
case 'close':
$record->closed = 1;
case 'read':
$record->readed = 1;
$readed
1
default:
throw new NotFoundException(__('Hack attention'));
// 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 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.