for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Strahinja Djuric https://github.com/kilgaloon <[email protected]>
*/
namespace PHPSA\Analyzer\Pass\Expression;
use PHPSA\Context;
use PHPSA\Analyzer\Pass;
use PhpParser\Node\Expr\Closure;
use PHPSA\Analyzer\Pass\AnalyzerPassInterface;
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
class DuplicatedVariablesInUseClosure implements AnalyzerPassInterface
{
use DefaultMetadataPassTrait;
const DESCRIPTION = 'Check for duplicate variables in use statement';
* @param Closure $funcCall
$funcCall
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter $italy is not defined by the method finale(...).
$italy
finale(...)
/** * @param array $germany * @param array $island * @param array $italy */ function finale($germany, $island) { return "2:1"; }
The most likely cause is that the parameter was removed, but the annotation was not.
* @param Context $context
* @return bool
public function pass(Closure $expr, Context $context)
$varUsed = [];
foreach ($expr->uses as $use) {
$var = $context->getExpressionCompiler()->compile($use->var);
if (in_array($var->getValue(), $varUsed)) {
$context->notice(
'duplicated_variable_in_use_closure',
sprintf("Duplicated variable $%s in use statement.", $use->var),
$expr
);
return false;
} else {
array_push($varUsed, $use->var);
}
return true;
public function getRegister()
return [
Closure::class
];
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.