PHPStan\Analyser\Scope::enterClassMethod PHP Method

enterClassMethod() public method

public enterClassMethod ( ClassMethod $classMethod, array $phpDocParameterTypes, PHPStan\Type\Type $phpDocReturnType = null ) : self
$classMethod PhpParser\Node\Stmt\ClassMethod
$phpDocParameterTypes array
$phpDocReturnType PHPStan\Type\Type
return self
    public function enterClassMethod(Node\Stmt\ClassMethod $classMethod, array $phpDocParameterTypes, Type $phpDocReturnType = null) : self
    {
        $isVariadic = false;
        foreach ($classMethod->params as $parameter) {
            if ($parameter->variadic) {
                $isVariadic = true;
            }
        }
        $realParameterTypes = [];
        foreach ($classMethod->params as $parameter) {
            $realParameterTypes[$parameter->name] = $this->getFunctionType($parameter->type, $this->isParameterValueNullable($parameter), $parameter->variadic);
        }
        return $this->enterFunction(new PhpMethodFromParserNodeReflection($this->getClass() !== null ? $this->broker->getClass($this->getClass()) : $this->getAnonymousClass(), $classMethod, $realParameterTypes, $phpDocParameterTypes, $classMethod->returnType !== null, $this->getFunctionType($classMethod->returnType, $classMethod->returnType === null, false), $phpDocReturnType, $isVariadic));
    }

Usage Example

Example #1
0
 private function enterClassMethod(Scope $scope, Node\Stmt\ClassMethod $classMethod) : Scope
 {
     $fileTypeMap = $this->fileTypeMapper->getTypeMap($scope->getFile());
     $phpDocParameterTypes = [];
     $phpDocReturnType = null;
     if ($classMethod->getDocComment() !== null) {
         $docComment = $classMethod->getDocComment()->getText();
         $phpDocParameterTypes = TypehintHelper::getPhpDocParameterTypesFromMethod($fileTypeMap, array_map(function (Param $parameter) : string {
             return $parameter->name;
         }, $classMethod->params), $docComment);
         $phpDocReturnType = TypehintHelper::getPhpDocReturnTypeFromMethod($fileTypeMap, $docComment);
     }
     return $scope->enterClassMethod($classMethod, $phpDocParameterTypes, $phpDocReturnType);
 }