mirror of https://github.com/rectorphp/rector.git
38 lines
965 B
PHP
38 lines
965 B
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\TypeDeclaration\NodeAnalyzer;
|
|
|
|
use PhpParser\Node\Expr;
|
|
use PhpParser\Node\Expr\Closure;
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use PhpParser\Node\Stmt\Function_;
|
|
use PhpParser\Node\Stmt\Return_;
|
|
final class ReturnAnalyzer
|
|
{
|
|
/**
|
|
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
|
|
*/
|
|
public function hasClassMethodRootReturn($functionLike) : bool
|
|
{
|
|
foreach ((array) $functionLike->stmts as $stmt) {
|
|
if ($stmt instanceof Return_) {
|
|
return \true;
|
|
}
|
|
}
|
|
return \false;
|
|
}
|
|
/**
|
|
* @param Return_[] $returns
|
|
*/
|
|
public function areExclusiveExprReturns(array $returns) : bool
|
|
{
|
|
foreach ($returns as $return) {
|
|
if (!$return->expr instanceof Expr) {
|
|
return \false;
|
|
}
|
|
}
|
|
return \true;
|
|
}
|
|
}
|