for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace app\helpers;
use Yii;
class Http
{
/**
* Call HTTP Exception
*
* @param int $code HTTP Status
* @param string $msg Message
* @throws HttpException when invoked
*/
public static function exception($code, $msg = null)
switch ($code) {
case 400:
$msg = $msg ? $msg : Yii::t('app', 'Bad request');
throw new \yii\web\BadRequestHttpException($msg);
break;
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
case 401:
$msg = $msg ? $msg : Yii::t('app', 'Access is unauthorized');
throw new \yii\web\UnauthorizedHttpException($msg);
case 403:
$msg = $msg ? $msg : Yii::t('app', 'Access Denied');
throw new \yii\web\ForbiddenHttpException($msg);
case 404:
default:
$msg = $msg ? $msg : Yii::t('app', 'Page not found');
throw new \yii\web\NotFoundHttpException($msg);
}
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.