for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Created by PhpStorm.
* User: djavolak
* Date: 10.9.16.
* Time: 16.11
*/
namespace Api\Controller;
* Class RestController.
* Base class for all controllers for REST API.
*
* @package Api\Controller
class RestController extends \Application\Mvc\Controller
{
* Render data from payload
* @throws \Api\Exception\NotImplementedException
* @return \Phalcon\Http\ResponseInterface
protected function render(\Api\Model\Payload $payload)
$format = $this->request->getQuery('format', null, 'json');
switch ($format)
case 'json':
$contentType = 'application/json';
$encoding = 'UTF-8';
$content = json_encode($payload->toArray());
break;
default:
throw new \Api\Exception\NotImplementedException(
sprintf('Requested format %s is not supported yet.', $format)
);
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
}
// $this->response->setStatusCode(200, 'OK');
$this->response->setContentType($contentType, $encoding);
$this->response->setContent($content);
return $this->response->send();
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.