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; }
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); }