Analyze class documentation block and extract annotated methods.

@param \Zend\Code\Reflection\DocBlockReflection $block Documentation block.
@return \Praxigento\Core\App\Reflection\Data\Method[]
191040
public function _processClassDocBlock($block)
    {
        $result = [];
        if ($block instanceof \Zend\Code\Reflection\DocBlockReflection) {
            $docBlockLines = $block->getContents();
            $docBlockLines = explode("\n", $docBlockLines);
            foreach ($docBlockLines as $line) {
                $methodData = $this->_processClassDocLine($line);
                if ($methodData) {
                    $name = $methodData->getName();
                    $result[$name] = $methodData;
                }
            }
        }
        return $result;
    }
664266
protected function getDocblockTagsSection($docblock)
    {
        $docblock = $this->sanitizeDocblock($docblock);
        preg_match('/^\s*\\'.self::TOKEN_ANNOTATION_IDENTIFIER.'/m', $docblock, $matches, PREG_OFFSET_CAPTURE);

        // return found docblock tag section or empty string
        return isset($matches[0]) ? substr($docblock, $matches[0][1]) : '';
    }
341860
protected function getReturnTypeFromDocBlock(\ReflectionMethod $reflection)
    {
        $type = null;
        $phpdoc = new DocBlock($reflection);

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

        return $type;
    }
1035362
public function processBlock(BlockDocument $block)
    {
        $hasMethods = false;

        $form = $this->formContainerService->getForm();
        if (!is_null($form) && $form->isSubmitted()) {
            $formBlockMethods = $block->getFormBlockMethods();

            /** @var FormBlockMethodArgumentDocument $formBlockMethod */
            foreach ($formBlockMethods as $formBlockMethod) {
                if ($method = $formBlockMethod->getMethodArgument()) {
                    $this->methodService->call($method);

                    if (!$hasMethods) {
                        $hasMethods = true;
                    }
                }
            }
        }

        return $hasMethods;
    }
1346832
private function getProxyMethods(): array
    {
        if (null !== $this->reflectionProxyMethods) {
            return $this->reflectionProxyMethods;
        }

        $proxyMethods = [];
        $methods = $this->getClassMethods();

        foreach ($methods as $method) {
            $docComment = $method->getDocComment();

            if (\strpos($docComment, 'Transactional') !== false) {
                $annotation = $this->annotationReader->getMethodAnnotation(
                    $method,
                    Transactional::class
                );

                if ($annotation) {
                    $proxyMethods[] = $method;
                }
            }
        }

        $this->reflectionProxyMethods = $proxyMethods;

        return $proxyMethods;
    }
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;
    }
416070
public function getCacheTags(ReadBlockInterface $block)
    {
        $tags = array();

        $nodes = $this->getNodes($block);
        $siteId = $this->currentSiteManager->getSiteId();
        $tags[] = $this->tagManager->formatMenuTag($siteId);

        if ($nodes) {
            foreach ($nodes as $node) {
                $tags[] = $this->tagManager->formatNodeIdTag($node->getNodeId());
            }
        }

        return $tags;
    }
288119
protected function getMethodName($method, $docBlock = null): string
    {
        if ($docBlock !== null && $docBlock->hasTag(self::API_METHOD_NAME)) {
            $tags = $docBlock->getTagsByName(self::API_METHOD_NAME);

            return (string)$tags[0];
        }

        $controllerName = $method->getDeclaringClass();

        if (!empty($this->server->endpoint)) {
            return $method->getName();
        }

        return $this->getShortNameForController($controllerName->getName()) . '_' . $method->getName();
    }
610598
public function getOffsetClasses(BlockInterface $block)
    {
        $classes = array();

        if ($block->getColumnCount()) {
            $properties = $block->getProperties();
            if (isset($properties['offsets']) && count($properties['offsets']) > 0) {
                foreach ($properties['offsets'] as $screen => $cols) {
                    if (!$cols) {
                        continue;
                    }
                    foreach ($cols as $col => $span) {
                        if (empty($span)) {
                            continue;
                        }
                        $classes[$col][] = "col-$screen-offset-$span";
                    }
                }
            }
        }

        return $classes;
    }
1302741
public function getCacheTags(ReadBlockInterface $block)
    {
        $tags = array();

        $medias = $block->getAttribute('pictures');

        if ($medias) {
            foreach ($medias as $media) {
                $tags[] = $this->tagManager->formatMediaIdTag($media['id']);
            }
        }

        return $tags;
    }
356597
public function getCacheKeys(BlockInterface $block)
    {
        $settings = $block->getSettings();

        $keys = parent::getCacheKeys($block);

        $keys['environment'] = $this->getContainer()->get('kernel')->getEnvironment();

        if (isset($settings['template'])) {
            $keys['template'] = $settings['template'];
        }

        if (isset($settings['id'])) {
            $key = $this->getName() . ':' . $settings['id'];

            if (isset($settings['template'])) {
                $key = $key . ':' . $settings['template'];
            }

            $keys['block_id'] = $key;
        }

        $keys['updated_at'] = '';

        return $keys;
    }
317525
private function parseAnnotations($docBlock, $pattern, callable $callback)
    {
        $annotations = [];
        // Strip away the docblock header and footer to ease parsing of one line annotations
        $docBlock = substr($docBlock, 3, -2);

        if (preg_match_all($pattern, $docBlock, $matches) && is_callable($callback)) {
            return call_user_func($callback, $matches);
        }

        return $annotations;
    }
1009849
protected function block(OutputBlock $block)
    {
        if (empty($block->lines) && empty($block->children)) {
            return;
        }

        $this->currentBlock = $block;

        $pre = $this->indentStr();

        if (! empty($block->selectors)) {
            $this->blockSelectors($block);

            $this->indentLevel++;
        }

        if (! empty($block->lines)) {
            $this->blockLines($block);
        }

        if (! empty($block->children)) {
            $this->blockChildren($block);
        }

        if (! empty($block->selectors)) {
            $this->indentLevel--;

            if (empty($block->children)) {
                $this->write($this->break);
            }

            $this->write($pre . $this->close . $this->break);
        }
    }
1029798
public function getAnnotationByKey($docBlock, $key)
    {
        /** @var array $classAnnotations */
        $classAnnotations = $this->parseCoverAnnotationDocBlock($docBlock);
        if (false === array_key_exists($key, $classAnnotations)) {
            return array();
        }

        return $classAnnotations[$key];
    }
460701
public static function fetchAnnotationsFromDocblock($annotation, $docblock)
    {
        if (preg_match_all(sprintf(self::$regex, $annotation), $docblock, $matched)) {
            return $matched[1];
        }
        return [];
    }
690034
protected function findParentButtons(BlockInterface $block)
    {
        if ($block->getAttribute('block_parent_buttons')) {
            return $block->getAttribute('block_parent_buttons');
        }

        $parent = $block;

        if ($block->getOption('scrollable')) {
            /* @var BlockInterface $block */
            foreach ($block->all() as $child) {
                if (BlockUtil::isBlockType($child, NavScrollableType::class)) {
                    /* @var BlockInterface $child */
                    foreach ($child->all() as $subChild) {
                        if (BlockUtil::isBlockType($subChild, BlockType::class)) {
                            $parent = $subChild;
                            break 2;
                        }
                    }
                }
            }
        }

        $block->setAttribute('block_parent_buttons', $parent);

        return $parent;
    }
1266933
private function finishBlock($block)
    {
        if (!array_key_exists($block, $this->blocks)) {
            throw new \Exception('Block '.$block.' not defined');
        }
        $this->blocks[$block]['total'] = $this->blocks[$block]['stop'] - $this->blocks[$block]['start'];

        return $this->blocks[$block];
    }