Generate docblock

@return array
546780
public function getElement()
    {
        if ($this->getDocblock()) {
            $this->setLines($this->getDocblock()->getElement());
            $this->addBlankLine();
        }
        if ($this->getNamespace()) {
            $this->addLine('namespace '.$this->getNamespace().';');
            $this->addBlankLine();
        }
        if (count($this->getUse()) > 0) {
            foreach ($this->getUse() as $alias => $class) {
                $line = 'use '.$class;
                if (is_string($alias)) {
                    $line .= ' as '.$alias;
                }
                $this->addLine($line.';');
            }
            $this->addBlankLine();
        }
        if ($this->getName()) {
            $this->addLine(
                ($this->isAbstract() ? 'abstract ' : '').'class '.$this->getName()
            );
        }
        if ($this->getExtends()) {
            $this->addLine(array('extends '.$this->getExtends()));
        }
        if (count($this->getImplements()) > 0) {
            $this->addLine(array('implements '.implode(', ', $this->getImplements())));
        }
        $this->startBlock();
        $this->addLine($this->getParams());
        $this->addLine($this->getFunctions());
        $this->endBlock();
        return $this->getLines();
    }
1372469
public function getThirdPartyBlocks()
    {
        /** @var Application $application */
        $application = $this->get('application');
        $embeddedComposer = $application->getEmbeddedComposer();
        $config = $embeddedComposer->getExternalComposerConfig();
        $loadBlock = $config->has('block-loader') ? $config->get('block-loader') : '.bldr/blocks.yml';
        $blockFile = $embeddedComposer->getExternalRootDirectory().DIRECTORY_SEPARATOR.$loadBlock;

        if (!file_exists($blockFile)) {
            return [];
        }

        $blockNames = Yaml::parse(file_get_contents($blockFile));
        if (null === $blockNames) {
            return [];
        }

        $blocks     = [];
        foreach ($blockNames as $block) {
            $blocks[] = new $block();
        }

        return $blocks;
    }
1219059
protected function createBlocks(BlockInterface $block)
    {
        $content = [];
        $content['id'] = $block->getId();
        $content['name'] = $block->getName();
        $content['enabled'] = $block->getEnabled();
        $content['position'] = $block->getPosition();
        $content['settings'] = $block->getSettings();
        $content['type'] = $block->getType();
        $content['created_at'] = $block->getCreatedAt()->format('U');
        $content['updated_at'] = $block->getUpdatedAt()->format('U');
        $content['blocks'] = [];

        foreach ($block->getChildren() as $child) {
            $content['blocks'][] = $this->createBlocks($child);
        }

        return $content;
    }
436668
function docBlock($lines) {
    if (!is_array($lines)) {
      $lines = array($lines);
    }

    $lines = array_merge(
      array("/**"),
      array_map(function ($line) {
        if (empty($line)) {
          return ' *';
        }
        return " * $line";
      }, $lines),
      array(" */")
    );

    return $lines;
  }
1048790
protected function generateTemplate()
    {
        $st_annotations = $this->extractAnnotations();

        $template = array();
        $counter = 0;
        $section = null;
        $partial_template = $this->loadPartialTemplate('main');

        foreach ($st_annotations as $class => $methods) {
            foreach ($methods as $name => $docs) {
                if (isset($docs['ApiDescription'][0]['section'])) {
                  $section = $docs['ApiDescription'][0]['section'];
                }elseif(isset($docs['ApiSector'][0]['name'])){
                    $section = $docs['ApiSector'][0]['name'];
                }else{
                    $section = $class;
                }
                if (0 === count($docs)) {
                    continue;
                }

                $sampleOutput = $this->generateSampleOutput($docs, $counter);

                $tr = array(
                    '{{ elt_id }}'                  => $counter,
                    '{{ method }}'                  => $this->generateBadgeForMethod($docs),
                    '{{ route }}'                   => $docs['ApiRoute'][0]['name'],
                    '{{ description }}'             => $docs['ApiDescription'][0]['description'],
                    '{{ headers }}'                 => $this->generateHeadersTemplate($counter, $docs),
                    '{{ parameters }}'              => $this->generateParamsTemplate($counter, $docs),
                    '{{ body }}'                    => $this->generateBodyTemplate($counter, $docs),
                    '{{ sandbox_form }}'            => $this->generateSandboxForm($docs, $counter),
                    '{{ sample_response_headers }}' => $sampleOutput[0],
                    '{{ sample_response_body }}'    => $sampleOutput[1]
                );

                $template[$section][] = strtr($partial_template, $tr);
                $counter++;
            }
        }

        $output = '';

        foreach ($template as $key => $value) {
          array_unshift($value, '<h2>' . $key . '</h2>');
          $output .= implode(PHP_EOL, $value);
        }

        $this->saveTemplate($output, $this->_output_file);

        return true;
    }
268604
public function generate()
    {
        $code = array();

        $doc = $this->generateDocumentation();
        if ($doc !== null) {
            $code[] = $doc;
        }

        $code[] = $this->getIndentation() . 'const ' . $this->name . ' = ' . $this->value->generate() . ';';

        return implode($this->getLineFeed(), $code);
    }
955335
public static function fetchAllAnnotationsFromDocblock($docblock)
    {
        $annotations = [];
        if (!preg_match_all(sprintf(self::$regex, '(\w+)'), $docblock, $matched)) {
            return $annotations;
        }
        foreach ($matched[1] as $k => $annotation) {
            if (!isset($annotations[$annotation])) {
                $annotations[$annotation] = [];
            }
            $annotations[$annotation][] = $matched[2][$k];
        };
        return $annotations;
    }
1362802
public function getBlockEndToken(): array
    {
        if (!$this->hasDocBlock()) {
            throw new DomainException(
                sprintf('Missing doc block for position %s of file %s.', $this->stackPos, $this->file->getFilename())
            );
        }

        return $this->tokens[$this->getBlockEndPosition()];
    }
273582
protected function getExtendedReturns($docBlock, array $current = []): array
    {
        $name = $docBlock->getVariableName();

        $nameParts = explode('.', $name);
        $variableName = array_shift($nameParts);

        /** @var SmdParameter $parameter */
        if (isset($current[$variableName])) {
            $parameter = $current[$variableName];
        } else {
            $parameter = new SmdParameter();
            $parameter->name = $variableName;
            $current[$variableName] = $parameter;
        }

        while ($key = array_shift($nameParts)) {
            $isArray = false;
            $variableName = $key;
            if (substr($variableName, -2) === '[]') {
                $variableName = substr($variableName, 0, -2);
                $isArray = true;
            }

            $parameter->types = ['object'];
            $parameters = $parameter->parameters;

            if (!isset($parameters[$variableName])) {
                $parameters[$variableName] = new SmdParameter();
            }

            $parameter->parameters = $parameters;
            $parameter = $parameters[$variableName];

            if ($isArray) {
                $parameter->array = true;
            }
        }

        $parameter->name = $variableName;

        $parameter = $this->checkParamType($parameter, $docBlock->getType());

        if (!empty((string)$docBlock->getDescription())) {
            $parameter->description = (string)$docBlock->getDescription();
        }

        if ($docBlock->isRoot()) {
            $parameter->is_root = true;
        }

        return $current;
    }
1034248
function doc(): Result {
    return $this->collectionBuilder()
      ->addTask($this->taskFilesystemStack()
        ->copy('CHANGELOG.md', 'doc/about/changelog.md')
        ->copy('LICENSE.md', 'doc/about/license.md'))
      ->addTask($this->taskExec('mkdocs build --config-file=etc/mkdocs.yaml'))
      ->addTask($this->taskFilesystemStack()
        ->remove(['doc/about/changelog.md', 'doc/about/license.md']))
      ->run();
  }
468391
public function createDocBlock($body = NULL) {
    $block = new DocBlock($body);
    $this->setDocBlock($block);
    return $block;
  }
148764
protected function generateParamDocblock() {
		$docblock = $this->getDocblock();
		$tags = $docblock->getTags('param');
		foreach ($this->parameters as $param) {
			$ptag = $param->getDocblockTag();

			$tag = $tags->find($ptag, function (ParamTag $tag, ParamTag $ptag) {
				return $tag->getVariable() == $ptag->getVariable();
			});

			// try to update existing docblock first
			if ($tag !== null) {
				$tag->setDescription($ptag->getDescription());
				$tag->setType($ptag->getType());
			}

			// ... append if it doesn't exist
			else {
				$docblock->appendTag($ptag);
			}
		}
	}
1294134
public function getDocComment(DocBlock $docblock): string
    {
        $indent = str_repeat($this->indentString, $this->indent);
        $firstIndent = $this->isFirstLineIndented ? $indent : '';
        // 3 === strlen(' * ')
        $wrapLength = $this->lineLength ? $this->lineLength - strlen($indent) - 3 : null;

        $text = $this->removeTrailingSpaces(
            $indent,
            $this->addAsterisksForEachLine(
                $indent,
                $this->getSummaryAndDescriptionTextBlock($docblock, $wrapLength)
            )
        );

        $comment = "{$firstIndent}/**\n";
        if ($text) {
            $comment .= "{$indent} * {$text}\n";
            $comment .= "{$indent} *\n";
        }

        $comment = $this->addTagBlock($docblock, $wrapLength, $indent, $comment);
        $comment .= $indent . ' */';

        return $comment;
    }
1062250
private function compactAnnotations($docblock)
    {
        $annotations = array();
        $index = -1;
        $inside = 0;
        $tokens = $this->tokenizer->parse($docblock);

        if (empty($tokens)) {
            return str_repeat("\n", substr_count($docblock, "\n"));
        }

        foreach ($tokens as $token) {
            if ((0 === $inside) && (DocLexer::T_AT === $token[0])) {
                $index++;
            } elseif (DocLexer::T_OPEN_PARENTHESIS === $token[0]) {
                $inside++;
            } elseif (DocLexer::T_CLOSE_PARENTHESIS === $token[0]) {
                $inside--;
            }

            if (!isset($annotations[$index])) {
                $annotations[$index] = array();
            }

            $annotations[$index][] = $token;
        }

        $breaks = substr_count($docblock, "\n");
        $docblock = "/**";

        foreach ($annotations as $annotation) {
            $annotation = new Tokens($annotation);
            $docblock .= "\n" . $this->converter->convert($annotation);
        }

        $breaks -= count($annotations);

        if ($breaks > 0) {
            $docblock .= str_repeat("\n", $breaks - 1);
            $docblock .= "\n*/";
        } else {
            $docblock .= ' */';
        }

        return $docblock;
    }
214106
protected function generatePartials()
    {
        $partials = $this->handlebars->getPartials();
        
        foreach ($partials as $name => $partial) {
            $partials[$name] = sprintf(
                self::BLOCK_OPTIONS_HASH_KEY_VALUE,
                $name,
                "'" . str_replace("'", '\\\'', $partial) . "'"
            );
        }
        
        return $this->prettyPrint(self::BLOCK_OPTIONS_OPEN)
            . $this->prettyPrint('\r\t')
            . implode($this->prettyPrint(',\r\t'), $partials)
            . $this->prettyPrint(self::BLOCK_OPTIONS_CLOSE);
    }
249370
public function parseCoverAnnotationDocBlock($docBlock)
    {
        $annotations = array('covers' => array(), 'uses' => array());
        $docBlock = substr($docBlock, 3, -2);
        if (preg_match_all('/@(?P<name>[A-Za-z_-]+)(?:[ \t]+(?P<value>.*?))?[ \t]*\r?$/m', $docBlock, $matches)) {
            $numMatches = count($matches[0]);
            for ($i = 0; $i < $numMatches; ++$i) {
                $annotations[$matches['name'][$i]][] = $matches['value'][$i];
            }
        }
        array_walk_recursive(
            $annotations,
            function(&$element) {
                if (substr($element, 0, 1) === '\\') {
                    $element = substr($element, 1);
                }
            }
        );
        return $annotations;
    }
1027102
public function getBlockTypes(): array
    {
        if ($this->_blockTypes !== null) {
            return $this->_blockTypes;
        }

        if ($this->getIsNew()) {
            return [];
        }

        return $this->_blockTypes = SuperTable::$plugin->getService()->getBlockTypesByFieldId($this->id);
    }