Пример #1
0
 public function getType() : Type
 {
     if ($this->type === null) {
         $phpDocType = $this->phpDocType;
         if ($phpDocType !== null && $this->reflection->isDefaultValueAvailable() && $this->reflection->getDefaultValue() === null) {
             $phpDocType = $phpDocType->makeNullable();
         }
         $this->type = TypehintHelper::decideTypeFromReflection($this->reflection->getType(), $phpDocType, $this->reflection->getDeclaringClass() !== null ? $this->reflection->getDeclaringClass()->getName() : null, $this->reflection->isVariadic());
     }
     return $this->type;
 }
 public function getReturnType() : Type
 {
     if ($this->returnType === null) {
         $phpDocReturnType = $this->phpDocReturnType;
         if ($this->realReturnTypePresent && $phpDocReturnType !== null && $this->realReturnType->isNullable() !== $phpDocReturnType->isNullable()) {
             $phpDocReturnType = null;
         }
         $this->returnType = TypehintHelper::decideType($this->realReturnType, $phpDocReturnType);
     }
     return $this->returnType;
 }
Пример #3
0
 public function getReturnType() : Type
 {
     if ($this->returnType === null) {
         $phpTypeReflection = $this->reflection->getReturnType();
         if ($phpTypeReflection === null) {
             $this->returnType = new MixedType(true);
         } else {
             $this->returnType = TypehintHelper::getTypeObjectFromTypehint((string) $phpTypeReflection, $phpTypeReflection->allowsNull());
         }
     }
     return $this->returnType;
 }
 /**
  * @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;
 }
Пример #5
0
 public function getReturnType() : Type
 {
     if ($this->returnType === null) {
         $returnType = $this->reflection->getReturnType();
         $phpDocReturnType = $this->phpDocReturnType;
         if ($returnType !== null && $phpDocReturnType !== null && $returnType->allowsNull() !== $phpDocReturnType->isNullable()) {
             $phpDocReturnType = null;
         }
         $this->returnType = TypehintHelper::decideTypeFromReflection($returnType, $phpDocReturnType, $this->declaringClass->getName());
     }
     return $this->returnType;
 }
Пример #6
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);
 }
Пример #7
0
 private function getTypeFromTypeString(string $typeString, string $className = null) : Type
 {
     $typeParts = explode('|', $typeString);
     $typePartsWithoutNull = array_values(array_filter($typeParts, function ($part) {
         return strtolower($part) !== 'null';
     }));
     if (count($typePartsWithoutNull) === 0) {
         return new NullType();
     }
     if (count($typePartsWithoutNull) !== 1) {
         return new MixedType(false);
     }
     $isNullable = count($typeParts) !== count($typePartsWithoutNull);
     return TypehintHelper::getTypeObjectFromTypehint($typePartsWithoutNull[0], $isNullable, $className);
 }
Пример #8
0
 public function getReturnType() : Type
 {
     if ($this->returnType === null) {
         $this->returnType = TypehintHelper::decideType($this->reflection->getReturnType(), $this->phpDocReturnType, $this->declaringClass->getName());
     }
     return $this->returnType;
 }