for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace PHPSA\Analyzer\Pass\Statement;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt;
use PHPSA\Analyzer\Helper\DefaultMetadataPassTrait;
use PHPSA\Analyzer\Helper\ResolveExpressionTrait;
use PHPSA\Analyzer\Pass;
use PHPSA\Context;
class ReturnAndYieldInOneMethod implements Pass\AnalyzerPassInterface
{
const DESCRIPTION = 'Checks for using return and yield statements in a one method and discourages it.';
use DefaultMetadataPassTrait;
use ResolveExpressionTrait;
/**
* @param Node\FunctionLike $func
* @param Context $context
* @return bool
*/
public function pass(Node\FunctionLike $func, Context $context)
$stmts = $func->getStmts();
if ($stmts === null) {
return false;
}
$yieldExists = \PHPSA\generatorHasValue($this->findYieldExpression($stmts));
if (!$yieldExists) {
// YieldFrom is another expression
$yieldExists = \PHPSA\generatorHasValue($this->findNode($stmts, Expr\YieldFrom::class));
if ($yieldExists && \PHPSA\generatorHasValue($this->findReturnStatement($stmts))) {
$context->notice('return_and_yield_in_one_method', 'Do not use return and yield in a one method', $func);
$func
object<PhpParser\Node\FunctionLike>
object<PhpParser\NodeAbstract>
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
return true;
* @return array
public function getRegister()
return [
Stmt\ClassMethod::class,
];
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: