<commit_before><?php

use Herbie\DI;
use Herbie\Hook;

class MenuPlugin
{

    public static function install()
    {
        Hook::attach('twigInitialized', ['MenuPlugin', 'addTwigFunctions']);
        Hook::attach('shortcodeInitialized', ['MenuPlugin', 'addShortcodes']);
    }

    public static function addTwigFunctions($twig)
    {
        $options = ['is_safe' => ['html']];
        $twig->addFunction(
            new \Twig_SimpleFunction('menu_ascii', ['MenuPlugin', 'functionAscii'], $options)
        );
        $twig->addFunction(
            new \Twig_SimpleFunction('menu_breadcrumb', ['MenuPlugin', 'functionBreadcrumb'], $options)
        );
        $twig->addFunction(
            new \Twig_SimpleFunction('menu_html', ['MenuPlugin', 'functionHtml'], $options)
        );
        $twig->addFunction(
            new \Twig_SimpleFunction('menu_sitemap', ['MenuPlugin', 'functionSitemap'], $options)
        );
    }

    public static function addShortcodes($shortcode)
    {
        $shortcode->add('menu_ascii', ['MenuPlugin', 'functionAsciiTree']);
        $shortcode->add('menu_breadcrumb', ['MenuPlugin', 'functionBreadcrumb']);
        $shortcode->add('menu_html', ['MenuPlugin', 'functionHtml']);
        $shortcode->add('menu_sitemap', ['MenuPlugin', 'functionSitemap']);
    }

    /**
     * @param array $options
     * @return string
     */
    public static function functionAsciiTree($options)
    {
        $options = (array)$options;
        extract($options); // showHidden, route, maxDepth, class
        $showHidden = isset($showHidden) ? (bool) $showHidden : false;
        $route = isset($route) ? (string)$route : '';
        $maxDepth = isset($maxDepth) ? (int)$maxDepth : -1;
        $class = isset($class) ? (string)$class : 'sitemap';

        $branch = DI::get('Menu\Page\Node')->findByRoute($route);
        $treeIterator = new Herbie\Menu\Page\Iterator\TreeIterator($branch);
        $filterIterator = new Herbie\Menu\Page\Iterator\FilterIterator($treeIterator);
        $filterIterator->setEnabled(!$showHidden);

        $asciiTree = new Herbie\Menu\Page\Renderer\AsciiTree($filterIterator);
        $asciiTree->setMaxDepth($maxDepth);
        return $asciiTree->render();
    }

    /**
     * @param array $options
     * @return string
     */
    public static function functionBreadcrumb($options)
    {
        // Options
        $options = (array)$options;
        extract($options);
        $delim = isset($delim) ? $delim : '';
        $homeLink = isset($homeLink) ? $homeLink : null;
        $reverse = isset($reverse) ? (bool) $reverse : false;

        $links = [];

        if (!empty($homeLink)) {
            if (is_array($homeLink)) {
                $route = reset($homeLink);
                $label = isset($homeLink[1]) ? $homeLink[1] : 'Home';
            } else {
                $route = $homeLink;
                $label = 'Home';
            }
            $links[] = static::createLink($route, $label);
        }

        foreach (DI::get('Menu\Page\RootPath') as $item) {
            $links[] = static::createLink($item->route, $item->getMenuTitle());
        }

        if (!empty($reverse)) {
            $links = array_reverse($links);
        }

        $html = '<ul class="breadcrumb">';
        foreach ($links as $link) {
            $html .= '<li>' . $link . '</li>';
        }
        $html .= '</ul>';

        return $html;
    }

    /**
     * @param array $options
     * @return string<commit_msg>Implement unused delimiter<commit_after><?php

use Herbie\DI;
use Herbie\Hook;

class MenuPlugin
{

    public static function install()
    {
        Hook::attach('twigInitialized', ['MenuPlugin', 'addTwigFunctions']);
        Hook::attach('shortcodeInitialized', ['MenuPlugin', 'addShortcodes']);
    }

    public static function addTwigFunctions($twig)
    {
        $options = ['is_safe' => ['html']];
        $twig->addFunction(
            new \Twig_SimpleFunction('menu_ascii', ['MenuPlugin', 'functionAscii'], $options)
        );
        $twig->addFunction(
            new \Twig_SimpleFunction('menu_breadcrumb', ['MenuPlugin', 'functionBreadcrumb'], $options)
        );
        $twig->addFunction(
            new \Twig_SimpleFunction('menu_html', ['MenuPlugin', 'functionHtml'], $options)
        );
        $twig->addFunction(
            new \Twig_SimpleFunction('menu_sitemap', ['MenuPlugin', 'functionSitemap'], $options)
        );
    }

    public static function addShortcodes($shortcode)
    {
        $shortcode->add('menu_ascii', ['MenuPlugin', 'functionAsciiTree']);
        $shortcode->add('menu_breadcrumb', ['MenuPlugin', 'functionBreadcrumb']);
        $shortcode->add('menu_html', ['MenuPlugin', 'functionHtml']);
        $shortcode->add('menu_sitemap', ['MenuPlugin', 'functionSitemap']);
    }

    /**
     * @param array $options
     * @return string
     */
    public static function functionAsciiTree($options)
    {
        $options = (array)$options;
        extract($options); // showHidden, route, maxDepth, class
        $showHidden = isset($showHidden) ? (bool) $showHidden : false;
        $route = isset($route) ? (string)$route : '';
        $maxDepth = isset($maxDepth) ? (int)$maxDepth : -1;
        $class = isset($class) ? (string)$class : 'sitemap';

        $branch = DI::get('Menu\Page\Node')->findByRoute($route);
        $treeIterator = new Herbie\Menu\Page\Iterator\TreeIterator($branch);
        $filterIterator = new Herbie\Menu\Page\Iterator\FilterIterator($treeIterator);
        $filterIterator->setEnabled(!$showHidden);

        $asciiTree = new Herbie\Menu\Page\Renderer\AsciiTree($filterIterator);
        $asciiTree->setMaxDepth($maxDepth);
        return $asciiTree->render();
    }

    /**
     * @param array $options
     * @return string
     */
    public static function functionBreadcrumb($options)
    {
        // Options
        $options = (array)$options;
        extract($options);
        $delim = isset($delim) ? $delim : '';
        $homeLink = isset($homeLink) ? $homeLink : null;
        $reverse = isset($reverse) ? (bool) $reverse : false;

        $links = [];

        if (!empty($homeLink)) {
            if (is_array($homeLink)) {
                $route = reset($homeLink);
                $label = isset($homeLink[1]) ? $homeLink[1] : 'Home';
            } else {
                $route = $homeLink;
                $label = 'Home';
            }
            $links[] = static::createLink($route, $label);
        }

        foreach (DI::get('Menu\Page\RootPath') as $item) {
            $links[] = static::createLink($item->route, $item->getMenuTitle());
        }

        if (!empty($reverse)) {
            $links = array_reverse($links);
        }

        $html = '<ul class="breadcrumb">';
        foreach ($links as $i => $link) {
            if ($i > 0 && !empty($delim)) {
                $html .= '<li class="delim">' . $delim . '</li>';
            }
            $html .= '<li>' . $link . '</li>';
        }
        $html .= '</ul>';

        return $html;
    }

    /**
     * @param array $options
     * @return string
{'fraction_non_alphanumeric': 0.16758048643329115, 'fraction_numerical': 0.0009841135948263741, 'mean_word_length': 2.392465426800191, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2025023', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2071, 'n_words': 383}