<commit_before><?php declare(strict_types=1);
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2017-2019, Darvin Studio
 * @link      https://www.darvin-studio.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Darvin\MenuBundle\Admin\View;

use Darvin\AdminBundle\EntityNamer\EntityNamerInterface;
use Darvin\AdminBundle\Route\AdminRouterInterface;
use Darvin\AdminBundle\Security\Permissions\Permission;
use Darvin\AdminBundle\View\Widget\Widget\AbstractWidget;
use Darvin\AdminBundle\View\Widget\Widget\ShowLinkWidget;
use Darvin\MenuBundle\Entity\Menu\Item;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
 * Slug map item link admin view widget
 */
class SlugMapItemLinkWidget extends AbstractWidget
{
    /**
     * @var \Darvin\AdminBundle\Route\AdminRouterInterface
     */
    private $adminRouter;

    /**
     * @var \Darvin\AdminBundle\EntityNamer\EntityNamerInterface
     */
    private $entityNamer;

    /**
     * @var \Darvin\AdminBundle\View\Widget\Widget\ShowLinkWidget
     */
    private $showLinkWidget;

    /**
     * @var \Symfony\Contracts\Translation\TranslatorInterface
     */
    private $translator;

    /**
     * @param \Darvin\AdminBundle\Route\AdminRouterInterface $adminRouter Admin router
     */
    public function setAdminRouter(AdminRouterInterface $adminRouter)
    {
        $this->adminRouter = $adminRouter;
    }

    /**
     * @param \Darvin\AdminBundle\EntityNamer\EntityNamerInterface $entityNamer Entity namer
     */
    public function setEntityNamer(EntityNamerInterface $entityNamer)
    {
        $this->entityNamer = $entityNamer;
    }

    /**
     * @param \Darvin\AdminBundle\View\Widget\Widget\ShowLinkWidget $showLinkWidget Show link admin view widget
     */
    public function setShowLinkWidget(ShowLinkWidget $showLinkWidget)
    {
        $this->showLinkWidget = $showLinkWidget;
    }

    /**
     * @param \Symfony\Contracts\Translation\TranslatorInterface $translator Translator
     */
    public function setTranslator(TranslatorInterface $translator)
    {
        $this->translator = $translator;
    }

    /**
     * @param \Darvin\MenuBundle\Entity\Menu\Item $menuItem Menu item
     * @param array                               $options  Options
     *
     * @return string
     */
    protected function createContent($menuItem, array $options): ?string
    {
        if (null === $menuItem->getSlugMapItem()) {
            return null;
        }

        $entity = $menuItem->getSlugMapItem()->getObject();

        if (empty($entity)) {
            return null;
        }

        $content = $this->translator->trans(
            sprintf('slug_map_item.%s.%s', $this->entityNamer->name($entity), $menuItem->getSlugMapItem()->getProperty()),
            [],
            'admin'
        );

        $showLink = $this->showLinkWidget->getContent($entity, [
            'text_link' => true,
        ]);

        return $content.(!empty($showLink) ? $showLink : $entity);
    }

    /**
     * {@inheritdoc}
     */
    protected function getAllowedEntityClasses(): array
    {
        return [
            Item::class,
        ];
    }

    /**
     * {@inheritdoc}
     */
    protected function getRequiredPermissions(): array
    {
        return [
            Permission::VIEW,
        ];
    }
}<commit_msg>Refactor admin view widgets.<commit_after><?php declare(strict_types=1);
/**
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2017-2019, Darvin Studio
 * @link      https://www.darvin-studio.ru
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Darvin\MenuBundle\Admin\View;

use Darvin\AdminBundle\EntityNamer\EntityNamerInterface;
use Darvin\AdminBundle\Route\AdminRouterInterface;
use Darvin\AdminBundle\Security\Permissions\Permission;
use Darvin\AdminBundle\View\Widget\Widget\AbstractWidget;
use Darvin\AdminBundle\View\Widget\Widget\ShowLinkWidget;
use Darvin\MenuBundle\Entity\Menu\Item;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
 * Slug map item link admin view widget
 */
class SlugMapItemLinkWidget extends AbstractWidget
{
    /**
     * @var \Darvin\AdminBundle\Route\AdminRouterInterface
     */
    private $adminRouter;

    /**
     * @var \Darvin\AdminBundle\EntityNamer\EntityNamerInterface
     */
    private $entityNamer;

    /**
     * @var \Darvin\AdminBundle\View\Widget\Widget\ShowLinkWidget
     */
    private $showLinkWidget;

    /**
     * @var \Symfony\Contracts\Translation\TranslatorInterface
     */
    private $translator;

    /**
     * @param \Darvin\AdminBundle\Route\AdminRouterInterface $adminRouter Admin router
     */
    public function setAdminRouter(AdminRouterInterface $adminRouter)
    {
        $this->adminRouter = $adminRouter;
    }

    /**
     * @param \Darvin\AdminBundle\EntityNamer\EntityNamerInterface $entityNamer Entity namer
     */
    public function setEntityNamer(EntityNamerInterface $entityNamer)
    {
        $this->entityNamer = $entityNamer;
    }

    /**
     * @param \Darvin\AdminBundle\View\Widget\Widget\ShowLinkWidget $showLinkWidget Show link admin view widget
     */
    public function setShowLinkWidget(ShowLinkWidget $showLinkWidget)
    {
        $this->showLinkWidget = $showLinkWidget;
    }

    /**
     * @param \Symfony\Contracts\Translation\TranslatorInterface $translator Translator
     */
    public function setTranslator(TranslatorInterface $translator)
    {
        $this->translator = $translator;
    }

    /**
     * @param \Darvin\MenuBundle\Entity\Menu\Item $menuItem Menu item
     * @param array                               $options  Options
     *
     * @return string
     */
    protected function createContent($menuItem, array $options): ?string
    {
        if (null === $menuItem->getSlugMapItem()) {
            return null;
        }

        $entity = $menuItem->getSlugMapItem()->getObject();

        if (empty($entity)) {
            return null;
        }

        $content = $this->translator->trans(
            sprintf('slug_map_item.%s.%s', $this->entityNamer->name($entity), $menuItem->getSlugMapItem()->getProperty()),
            [],
            'admin'
        );

        $showLink = $this->showLinkWidget->getContent($entity, [
            'text_link' => true,
        ]);

        return $content.(!empty($showLink) ? $showLink : $entity);
    }

    /**
     * {@inheritdoc}
     */
    protected function getAllowedEntityClasses(): iterable
    {
        yield Item::class;
    }

    /**
     * {@inheritdoc}
     */
    protected function getRequiredPermissions(): iterable
    {
        yield Permission::VIEW;
    }
}
{'fraction_non_alphanumeric': 0.12005878030859662, 'fraction_numerical': 0.002645113886847906, 'mean_word_length': 2.6221394358701438, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1669991', 'n_tokens_mistral': 2002, 'n_tokens_neox': 1950, 'n_words': 357}