<commit_before><?php
namespace Skillberto\SonataPageMenuBundle\MenuBuilder;

use Doctrine\Common\Persistence\ManagerRegistry;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Skillberto\SonataPageMenuBundle\Entity\Menu;
use Sonata\PageBundle\Entity\PageManager;
use Sonata\PageBundle\Route\CmsPageRouter;
use Sonata\PageBundle\Site\SiteSelectorInterface;
use Symfony\Cmf\Component\Routing\ChainedRouterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

class MainMenuBuilder implements MenuBuilderInterface
{
    protected
        $menuEntity,
        $factoryInterface,
        $managerRegistry,
        $routerInterface,
        $siteSelectorInterface,
        $currentMenuName = null,
        $rendered = false,
        $mainMenu,
        $request;

    public function __construct($menuEntity, FactoryInterface $factoryInterface, ManagerRegistry $managerRegistry, RequestStack $requestStack, ChainedRouterInterface $routerInterface, SiteSelectorInterface $siteSelectorInterface)
    {
        $this->menuEntity               = $menuEntity;
        $this->factoryInterface         = $factoryInterface;
        $this->managerRegistry          = $managerRegistry;
        $this->request                  = $requestStack->getCurrentRequest();;
        $this->routerInterface          = $routerInterface;
        $this->siteSelectorInterface    = $siteSelectorInterface;
    }
    
    public function getMenu()
    {
        if ($this->rendered === false) {
            $this->renderMenu();

            $this->rendered = true;
        }

        return $this->mainMenu;
    }

    public function getCurrentMenuName()
    {
        return $this->currentMenuName;
    }

    protected function renderMenu()
    {
        $site    = $this->siteSelectorInterface->retrieve();

        $menus   = $this->managerRegistry->getRepository($this->menuEntity)->findBy(array("site" => $site->getId(), "parent" => null), array("root" => "ASC", "lft" => "ASC"));

        $this->createMenuStructure($menus);
    }

    protected function createMenuStructure($menus, ItemInterface $root = null)<commit_msg>empty menu entity bug fix<commit_after><?php
namespace Skillberto\SonataPageMenuBundle\MenuBuilder;

use Doctrine\Common\Persistence\ManagerRegistry;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Skillberto\SonataPageMenuBundle\Entity\Menu;
use Sonata\PageBundle\Entity\PageManager;
use Sonata\PageBundle\Route\CmsPageRouter;
use Sonata\PageBundle\Site\SiteSelectorInterface;
use Symfony\Cmf\Component\Routing\ChainedRouterInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

class MainMenuBuilder implements MenuBuilderInterface
{
    protected
        $menuEntity,
        $factoryInterface,
        $managerRegistry,
        $routerInterface,
        $siteSelectorInterface,
        $currentMenuName = null,
        $rendered = false,
        $mainMenu,
        $request;

    public function __construct($menuEntity, FactoryInterface $factoryInterface, ManagerRegistry $managerRegistry, RequestStack $requestStack, ChainedRouterInterface $routerInterface, SiteSelectorInterface $siteSelectorInterface)
    {
        $this->menuEntity               = $menuEntity;
        $this->factoryInterface         = $factoryInterface;
        $this->managerRegistry          = $managerRegistry;
        $this->request                  = $requestStack->getCurrentRequest();;
        $this->routerInterface          = $routerInterface;
        $this->siteSelectorInterface    = $siteSelectorInterface;
    }
    
    public function getMenu()
    {
        if ($this->rendered === false) {
            $this->renderMenu();

            $this->rendered = true;
        }

        return $this->mainMenu;
    }

    public function getCurrentMenuName()
    {
        return $this->currentMenuName;
    }

    protected function renderMenu()
    {
        $site    = $this->siteSelectorInterface->retrieve();

        $menus   = $this->managerRegistry->getRepository($this->menuEntity)->findBy(array("site" => $site->getId(), "parent" => null), array("root" => "ASC", "lft" => "ASC"));

        if (count($menus) == 0) {
            $this->mainMenu = $this->factoryInterface->createItem('root');

            return;
        }

        $this->createMenuStructure($menus);
    }

    protected function createMenuStructure($menus, ItemInterface $root = null)
{'fraction_non_alphanumeric': 0.11108632612090118, 'fraction_numerical': 0.00022306491188935982, 'mean_word_length': 3.1137614678899084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, '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': '5425772', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1172, 'n_words': 211}