Get method return type based on it DocBlock comment

@param \ReflectionMethod $reflection

@return null|string
341860
protected function getReturnTypeFromDocBlock(\ReflectionMethod $reflection)
    {
        $type = null;
        $phpdoc = new DocBlock($reflection);

        if ($phpdoc->hasTag('return')) {
            $type = $phpdoc->getTagsByName('return')[0]->getType();
        }

        return $type;
    }
971741
private function getMethod(\ReflectionMethod $method)
    {
        $methodStmt = $this->factory->method($method->name);
        $params = $method->getParameters();
        foreach ($params as $param) {
            $methodStmt = $this->getMethodStatement($param, $methodStmt);
        }
        $returnType = $method->getReturnType();
        if ($returnType instanceof \ReflectionType) {
            $this->setReturnType($returnType, $methodStmt);
        }
        $methodInsideStatements = $this->getMethodInsideStatement($method);
        $methodStmt->addStmts($methodInsideStatements);

        return $this->addMethodDocComment($methodStmt, $method);
    }
1348881
protected function getDocBlockReturnType(array $return, array $uses): string
    {
        $return = array_shift($return);
        $type = $return['type'] ?: '';

        $types = [];
        foreach (explode('|', $type) as $tmpType) {
            if (isset($uses[$tmpType])) {
                $tmpType = $uses[$tmpType];
            }
            $types[] = strpos($tmpType, '\\') === 0 ? substr($tmpType, 1) : $tmpType;
        }

        return implode('|', $types);
    }
844652
protected function getCommentType($propertyType)
    {
        $commentType = 'string';
        if (stripos($propertyType, 'int') !== false) {
            $commentType = 'integer';
        } else if (stripos($propertyType, 'float') !== false) {
            $commentType = 'float';
        } else if (stripos($propertyType, 'decimal') !== false) {
            $commentType = 'double';
        }

        return $commentType;
    }
1301869
public function getDocComment($prefix = "\t\t")
    {
        $serializer = new DocBlockSerializer(1, $prefix);

        if ($this->phpdoc) {
            if ($this->config->get('ide-helper.include_class_docblocks')) {
                // if a class doesn't expose any DocBlock tags
                // we can perform reflection on the class and
                // add in the original class DocBlock
                if (count($this->phpdoc->getTags()) === 0) {
                    $class = new ReflectionClass($this->root);
                    $this->phpdoc = new DocBlock($class->getDocComment());
                }
            }

            $this->removeDuplicateMethodsFromPhpDoc();
            return $serializer->getDocComment($this->phpdoc);
        }

        return '';
    }
915032
public function getPrototype(ReflectionMethod $method)
    {
        $modifiers =
            implode(' ', Reflection::getModifierNames($method->getModifiers()));
        if ($this->hideAbstract) {
            $modifiers = str_replace('abstract ', '', $modifiers);
        }
        $parameters = array();
        foreach ($method->getParameters() as $p) {
            $param = $this->getTypeHint($p);
            $param .= $this->getName($p);
            $param .= $this->getDefaultValue($p);
            $parameters[] = $param;
        }

        return $modifiers . ' function ' . $method->getName() . "(" .
        implode(', ', $parameters) . ")";
    }
1157917
protected function getMethodReturn($method, $docBlock = null): SmdReturn
    {
        $result = new SmdReturn();
        $result->types = ['mixed'];

        if (PHP_VERSION_ID > 70000) {
            $result->types = [$method->getReturnType()];
        }

        if ($docBlock !== null && $docBlock->hasTag(self::API_METHOD_RETURN)) {
            /** @var DocBlock\Tags\Return_ $return */
            $return = $docBlock->getTagsByName(self::API_METHOD_RETURN)[0];
            if (!empty((string)$return->getType())) {
                $result->types = explode('|', (string)$return->getType());
            }
            if (!empty((string)$return->getDescription())) {
                $result->description = (string)$return->getDescription();
            }
        }

        return $result;
    }
102787
public function getDocComment(): ?Doc
    {
        $docComment = $this->classConstants->consts[$this->index]->getDocComment();
        if ($docComment === null) {
            $docComment = $this->classConstants->getDocComment();
        }

        return $docComment;
    }
511399
public function getType() : ?string 
    {
        if ( ! $this->hasType()) {
            $this->setType($this->getDefaultType());
        }
        return $this->type;
    }
1156844
protected function readAllAnnotationsFor($reflection)
    {
        // Construct Method to be used for reading.
        $methodName = $this->constructReadMethod();

        // Read, Collect and return annotations.
        return collect($this->reader->{$methodName}($reflection));
    }
678393
private function getReturnType(DocBlock $docBlock)
    {
        // The @return tag will be present for each getter method of generated
        // classes. There is always only one tag for each getter.
        return ($docBlock->hasTag('return')) ?
            strval($docBlock->getTags()[0]->getType()) : null;
    }
353980
public function getMethodBody(string $methodName, ReflectionClass $reflectionClass): string
    {
        $method      = $reflectionClass->getMethod($methodName);
        $startLine   = $method->getStartLine() - 1;
        $length      = $method->getEndLine() - $startLine;
        $lines       = file($reflectionClass->getFileName());
        $methodLines = \array_slice($lines, $startLine, $length);

        return implode('', $methodLines);
    }
1066979
private function getMethodReturnType(\ReflectionMethod $method)
    {
        if ( ! $method->hasReturnType()) {
            return '';
        }

        return ': ' . $this->formatType($method->getReturnType(), $method);
    }
745993
private function getMethodCallbacks(\ReflectionMethod $method)
    {
        $callbacks   = array();
        $annotations = $this->reader->getMethodAnnotations($method);

        foreach ($annotations as $annot) {
            if ($annot instanceof \Doctrine\ORM\Mapping\PrePersist) {
                $callbacks[] = array($method->name, Events::prePersist);
            }

            if ($annot instanceof \Doctrine\ORM\Mapping\PostPersist) {
                $callbacks[] = array($method->name, Events::postPersist);
            }

            if ($annot instanceof \Doctrine\ORM\Mapping\PreUpdate) {
                $callbacks[] = array($method->name, Events::preUpdate);
            }

            if ($annot instanceof \Doctrine\ORM\Mapping\PostUpdate) {
                $callbacks[] = array($method->name, Events::postUpdate);
            }

            if ($annot instanceof \Doctrine\ORM\Mapping\PreRemove) {
                $callbacks[] = array($method->name, Events::preRemove);
            }

            if ($annot instanceof \Doctrine\ORM\Mapping\PostRemove) {
                $callbacks[] = array($method->name, Events::postRemove);
            }

            if ($annot instanceof \Doctrine\ORM\Mapping\PostLoad) {
                $callbacks[] = array($method->name, Events::postLoad);
            }

            if ($annot instanceof \Doctrine\ORM\Mapping\PreFlush) {
                $callbacks[] = array($method->name, Events::preFlush);
            }
        }

        return $callbacks;
    }
1036780
private static function getParameterTemplate(\ReflectionMethod $reflectionMethod): string
    {
        $template = '';
        $reflectionParameters = $reflectionMethod->getParameters();
        $paramCount = \count($reflectionParameters);
        foreach ($reflectionParameters as $reflectionParameter) {
            $paramCount--;
            // Parameter type
            $type = $reflectionParameter->getType();
            if ($type !== null) {
                $type = $type->__toString();
                $template .= " $type ";
            }

            // Parameter name
            $paramName = $reflectionParameter->getName();
            if ($reflectionParameter->isPassedByReference()) {
                $template .= " &\${$paramName} ";
            } elseif ($reflectionParameter->isVariadic()) {
                $template .= " ...\${$paramName} ";
            } else {
                $template .= " \${$paramName} ";
            }

            // Parameter default value
            if ($reflectionParameter->isOptional() && $reflectionParameter->isVariadic() === false) {
                $template .= self::getParameterDefaultValue($reflectionParameter);
            }

            if ($paramCount !== 0) {
                $template .= ',';
            }
        }

        return $template;
    }
1131141
public function getMethods($type)
    {
        $result = [];
        if ($type !== false) {
            $typeNorm = $this->toolsType->normalizeType($type);
            /** @var \Zend\Code\Reflection\ClassReflection $reflection */
            $reflection = new \Zend\Code\Reflection\ClassReflection($typeNorm);
            /** @var \Zend\Code\Reflection\DocBlockReflection $docBlock */
            $docBlock = $reflection->getDocBlock();
            $annotatedMethods = $this->_processClassDocBlock($docBlock);
            /* process normal methods (not annotated) */
            $publicMethods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
            $generalMethods = $this->_processClassMethods($publicMethods);
            $merged = array_merge($generalMethods, $annotatedMethods);
            /* convert results to array form according Magento requirements to be saved in the cache */
            /** @var \Praxigento\Core\App\Reflection\Data\Method $item */
            foreach ($merged as $item) {
                $methodName = $item->getName();
                $entry = [
                    'type' => $item->getType(),
                    'isRequired' => $item->getIsRequired(),
                    'description' => $item->getDescription(),
                    'parameterCount' => $item->getParameterCount()
                ];
                $result[$methodName] = $entry;
            }
        }
        return $result;
    }
700098
protected function getClassMeta(ReflectionClass $reflection): array
    {
        $doc = $reflection->getDocComment();
        $notations = $this->parser->parse($doc);

        return $notations;
    }