<commit_before><?php
/**
 * Class Link | Link.php
 * @package Faulancer\View\Helper
 * @author  <NAME> <<EMAIL>>
 */
namespace Faulancer\View\Helper;

use Faulancer\Exception\RouteInvalidException;
use Faulancer\Http\Request;
use Faulancer\Service\Config;
use Faulancer\Service\RequestService;
use Faulancer\Translate\Translator;
use Faulancer\View\AbstractViewHelper;
use Faulancer\View\ViewController;

/**
 * Class Link
 */
class Link extends AbstractViewHelper
{

    /**
     * @param ViewController $view
     * @param string         $routeName
     * @param array          $elementAttributes
     * @return string
     * @throws RouteInvalidException
     * @codeCoverageIgnore
     */
    public function __invoke(ViewController $view, $routeName, $elementAttributes = [])
    {
        $id    = '';
        $class = '';
        $style = '';

        $serviceLocator = $this->getServiceLocator();

        /** @var Config $config */
        $config = $serviceLocator->get(Config::class);

        /** @var Request $request */
        $request = $serviceLocator->get(RequestService::class);

        $route = $config->get('routes:' . $routeName);

        if (empty($route)) {
            throw new RouteInvalidException('No valid route for "' . $routeName . '" found.');
        }

        if ($request->getUri() === $route['path']) {
            $elementAttributes['class'][] = 'selected';
        }

        if (!empty($elementAttributes['id'])) {
            $id = ' id="' . implode(' ', $elementAttributes['id']) . '" ';
        }

        if (!empty($elementAttributes['class'])){
            $class = 'class="' . implode(' ', $elementAttributes['class']) . '" ';
        }

        if (!empty($elementAttributes['style'])) {
            $style = 'style="' . implode(' ', $elementAttributes['style']) . '" ';
        }

        $linkPattern = '<a ' . $id . $class . $style . 'href="%s" onfocus="blur()">%s</a>';

        if (!empty($route['i18n_key'])) {
            $translator = new Translator();
            $route['title'] = $translator->translate($route['i18n_key']);
        }<commit_msg>Show translation key only if title exists in routes<commit_after><?php
/**
 * Class Link | Link.php
 * @package Faulancer\View\Helper
 * @author  <NAME> <<EMAIL>>
 */
namespace Faulancer\View\Helper;

use Faulancer\Exception\RouteInvalidException;
use Faulancer\Http\Request;
use Faulancer\Service\Config;
use Faulancer\Service\RequestService;
use Faulancer\Translate\Translator;
use Faulancer\View\AbstractViewHelper;
use Faulancer\View\ViewController;

/**
 * Class Link
 */
class Link extends AbstractViewHelper
{

    /**
     * @param ViewController $view
     * @param string         $routeName
     * @param array          $elementAttributes
     * @return string
     * @throws RouteInvalidException
     * @codeCoverageIgnore
     */
    public function __invoke(ViewController $view, $routeName, $elementAttributes = [])
    {
        $id    = '';
        $class = '';
        $style = '';

        $serviceLocator = $this->getServiceLocator();

        /** @var Config $config */
        $config = $serviceLocator->get(Config::class);

        /** @var Request $request */
        $request = $serviceLocator->get(RequestService::class);

        $route = $config->get('routes:' . $routeName);

        if (empty($route)) {
            throw new RouteInvalidException('No valid route for "' . $routeName . '" found.');
        }

        if ($request->getUri() === $route['path']) {
            $elementAttributes['class'][] = 'selected';
        }

        if (!empty($elementAttributes['id'])) {
            $id = ' id="' . implode(' ', $elementAttributes['id']) . '" ';
        }

        if (!empty($elementAttributes['class'])){
            $class = 'class="' . implode(' ', $elementAttributes['class']) . '" ';
        }

        if (!empty($elementAttributes['style'])) {
            $style = 'style="' . implode(' ', $elementAttributes['style']) . '" ';
        }

        $linkPattern = '<a ' . $id . $class . $style . 'href="%s" onfocus="blur()">%s</a>';

        if (!empty($route['i18n_key']) && !empty($route['title'])) {
            $translator = new Translator();
            $route['title'] = $translator->translate($route['i18n_key']);
        }
{'fraction_non_alphanumeric': 0.1752745968684272, 'fraction_numerical': 0.0018695956999298902, 'mean_word_length': 2.5756056808688386, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, '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': '3361709', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1217, 'n_words': 241}