for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Patsura Dmitry https://github.com/ovr <[email protected]>
*/
namespace PHPSA\Analyzer\Pass\FunctionCall;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PHPSA\Compiler\Expression;
use PHPSA\Context;
class DebugCode implements PassFunctionCallInterface
{
protected $map = array(
'var_dump' => 'var_dump',
'var_export' => 'var_export',
'debug_zval_dump' => 'debug_zval_dump'
);
public function pass(FuncCall $funcCall, Context $context)
$compiler = $context->getExpressionCompiler();
$funcNameCompiledExpression = $compiler->compile($funcCall->name);
$funcNameCompiledExpression
20
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.
if ($funcNameCompiledExpression->isString() && $funcNameCompiledExpression->isCorrectValue()) {
$name = $funcNameCompiledExpression->getValue();
} else {
$context->debug(
'Unexpected function name type ' . $funcNameCompiledExpression->getType(),
$funcCall->name
return false;
}
if (isset($this->map[$name])) {
if ($funcCall->getDocComment()) {
$phpdoc = new \phpDocumentor\Reflection\DocBlock($funcCall->getDocComment()->getText());
if ($phpdoc->hasTag('expected')) {
return true;
$context->notice(
'debug.code',
sprintf('Function %s() is a debug code, please don`t use it in production.', $name),
$funcCall
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.