<?php
/**
 * @var string $classNamespace
 * @var \Zephir\Class\Method\Method $method
 */

$allTypes = [];

foreach ($method->getReturnClassTypes() as $c) {
    if ('\\' == $c[0]) {
        $allTypes[] = substr($c,1);
        continue;
    }

    $aliasManager = $method->getClassDefinition()->getAliasManager();

    $returnClassType = "{$classNamespace}\\{$c}";
    if ($aliasManager->isAlias($c)) {
        $returnClassType = '\\'.$aliasManager->getAlias($c);
    }

    $allTypes[] = sprintf(
        '<a href="%s">%s</a>',
        $this->url(Zephir\Documentation::classUrl($returnClassType)),
        $returnClassType
    );
}

$types = $method->getReturnTypes();

if ($types && count($types)>0 ) {
    foreach ($types as $type) {
        if ($type && isset($type['data-type'])) {
            $allTypes[] =  $type['data-type'];
        }
    }
}

$docblock = $method->getParsedDocblock();
?>

<li class="class-method clearfix">
    <div class="method-summary">
        <div class="method-signature">
            <!-- method-summary -->
            <!-- Do not remove comments below. It's a trick to remove the spaces. -->
            <span class="method-name">
                <a href="#method-details-<?= $method->getName() ?>"><?= $method->getName() ?></a><!--
            --></span><!--
            -->(<?= $this->partial('partials/class/method-summary-params.phtml') ?>)<!--
            --><span class="method-return">
                <strong>:</strong>
                <?php if (!empty($allTypes)):?>
                    <?php echo join(' | ', $allTypes); ?>
                <?php else: ?>
                    void
                <?php endif; ?>
            </span>
        </div>
        <?php if ($docblock): ?>
            <div class="method-doc">
                <div class="summary-text">
                    <?php echo $docblock->getSummary(); ?>
                </div>
            </div>
        <?php endif; ?>
    </div>
</li>
