PHPStan\Rules\FunctionReturnTypeCheck::checkReturnType PHP 메소드

checkReturnType() 공개 메소드

public checkReturnType ( Scope $scope, PHPStan\Type\Type $returnType, PhpParser\Node\Expr $returnValue = null, string $emptyReturnStatementMessage, string $voidMessage, string $typeMismatchMessage ) : array
$scope PHPStan\Analyser\Scope
$returnType PHPStan\Type\Type
$returnValue PhpParser\Node\Expr
$emptyReturnStatementMessage string
$voidMessage string
$typeMismatchMessage string
리턴 array
    public function checkReturnType(Scope $scope, Type $returnType, Expr $returnValue = null, string $emptyReturnStatementMessage, string $voidMessage, string $typeMismatchMessage) : array
    {
        if ($returnValue === null) {
            if ($returnType instanceof VoidType || $returnType instanceof MixedType) {
                return [];
            }
            return [sprintf($emptyReturnStatementMessage, $returnType->describe())];
        }
        $returnValueType = $scope->getType($returnValue);
        if ($returnType instanceof VoidType) {
            return [sprintf($voidMessage, $returnValueType->describe())];
        }
        if (!$returnType->accepts($returnValueType)) {
            return [sprintf($typeMismatchMessage, $returnType->describe(), $returnValueType->describe())];
        }
        return [];
    }

Usage Example

예제 #1
0
 /**
  * @param \PhpParser\Node\Stmt\Return_ $node
  * @param \PHPStan\Analyser\Scope $scope
  * @return string[]
  */
 public function processNode(Node $node, Scope $scope) : array
 {
     if (!$scope->isInAnonymousFunction()) {
         return [];
     }
     return $this->returnTypeCheck->checkReturnType($scope, $scope->getAnonymousFunctionReturnType(), $node->expr, 'Anonymous function should return %s but empty return statement found.', 'Anonymous function with return type void returns %s but should not return anything.', 'Anonymous function should return %s but returns %s.');
 }
All Usage Examples Of PHPStan\Rules\FunctionReturnTypeCheck::checkReturnType
FunctionReturnTypeCheck