getPhpDocReturnTypeFromMethod() public static method

public static getPhpDocReturnTypeFromMethod ( array $typeMap, string $docComment ) : PHPStan\Type\Type | null
$typeMap array
$docComment string
return PHPStan\Type\Type | null
コード例 #1
0
 /**
  * @param \PHPStan\Reflection\ClassReflection $classReflection
  * @return \PHPStan\Reflection\MethodReflection[]
  */
 private function createMethods(ClassReflection $classReflection) : array
 {
     $methods = [];
     foreach ($classReflection->getNativeReflection()->getMethods() as $methodReflection) {
         $declaringClass = $this->broker->getClass($methodReflection->getDeclaringClass()->getName());
         $phpDocParameterTypes = [];
         $phpDocReturnType = null;
         if (!$declaringClass->getNativeReflection()->isAnonymous() && $declaringClass->getNativeReflection()->getFileName() !== false) {
             $typeMap = $this->fileTypeMapper->getTypeMap($declaringClass->getNativeReflection()->getFileName());
             if ($methodReflection->getDocComment() !== false) {
                 $phpDocParameterTypes = TypehintHelper::getPhpDocParameterTypesFromMethod($typeMap, array_map(function (\ReflectionParameter $parameterReflection) : string {
                     return $parameterReflection->getName();
                 }, $methodReflection->getParameters()), $methodReflection->getDocComment());
             }
             if ($methodReflection->getDocComment() !== false) {
                 $phpDocReturnType = TypehintHelper::getPhpDocReturnTypeFromMethod($typeMap, $methodReflection->getDocComment());
             }
         }
         $methods[strtolower($methodReflection->getName())] = $this->methodReflectionFactory->create($declaringClass, $methodReflection, $phpDocParameterTypes, $phpDocReturnType);
     }
     return $methods;
 }
コード例 #2
0
ファイル: NodeScopeResolver.php プロジェクト: phpstan/phpstan
 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);
 }