<commit_before><?php
/**
 * Created by PhpStorm.
 * User: imanu
 * Date: 04.03.2018
 * Time: 18:59
 */

namespace Jinya\Controller\Api\Menu;

use Jinya\Entity\Menu\MenuItem;
use Jinya\Entity\Menu\RoutingEntry;
use Jinya\Exceptions\MissingFieldsException;
use Jinya\Formatter\Menu\MenuFormatterInterface;
use Jinya\Formatter\Menu\MenuItemFormatterInterface;
use Jinya\Framework\BaseApiController;
use Jinya\Services\Menu\MenuItemServiceInterface;
use Jinya\Services\Menu\MenuServiceInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use function array_key_exists;
use function array_map;

class MenuItemController extends BaseApiController
{
    /**
     * @Route("/api/menu/{id}/items", methods={"GET"}, name="api_menu_items_get_all")
     *
     * @param int $id
     * @param MenuItemServiceInterface $menuItemService
     * @param MenuItemFormatterInterface $menuItemFormatter
     * @return Response
     */
    public function getAllAction(
        int $id,
        MenuItemServiceInterface $menuItemService,
        MenuItemFormatterInterface $menuItemFormatter
    ): Response {
        [$data, $status] = $this->tryExecute(static function () use ($id, $menuItemService, $menuItemFormatter) {
            return array_map(static function ($item) use ($menuItemFormatter) {
                return $menuItemFormatter
                    ->init($item)
                    ->title()
                    ->position()
                    ->route()
                    ->children()
                    ->highlighted()
                    ->format();
            }, $menuItemService->getAll($id, MenuItemServiceInterface::MENU));
        });

        return $this->json($data, $status);
    }

    /**
     * @Route("/api/menu/{id}/items/{position}", methods={"GET"}, name="api_menu_items_get")
     *
     * @param int $id
     * @param int $position
     * @param MenuItemServiceInterface $menuItemService
     * @param MenuItemFormatterInterface $menuItemFormatter
     * @return Response
     */
    public function getAction(
        int $id,<commit_msg>CHORE: Added missing menu item properties<commit_after><?php
/**
 * Created by PhpStorm.
 * User: imanu
 * Date: 04.03.2018
 * Time: 18:59
 */

namespace Jinya\Controller\Api\Menu;

use Jinya\Entity\Menu\MenuItem;
use Jinya\Entity\Menu\RoutingEntry;
use Jinya\Exceptions\MissingFieldsException;
use Jinya\Formatter\Menu\MenuFormatterInterface;
use Jinya\Formatter\Menu\MenuItemFormatterInterface;
use Jinya\Framework\BaseApiController;
use Jinya\Services\Menu\MenuItemServiceInterface;
use Jinya\Services\Menu\MenuServiceInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use function array_key_exists;
use function array_map;

class MenuItemController extends BaseApiController
{
    /**
     * @Route("/api/menu/{id}/items", methods={"GET"}, name="api_menu_items_get_all")
     *
     * @param int $id
     * @param MenuItemServiceInterface $menuItemService
     * @param MenuItemFormatterInterface $menuItemFormatter
     * @return Response
     */
    public function getAllAction(
        int $id,
        MenuItemServiceInterface $menuItemService,
        MenuItemFormatterInterface $menuItemFormatter
    ): Response {
        [$data, $status] = $this->tryExecute(static function () use ($id, $menuItemService, $menuItemFormatter) {
            return array_map(static function ($item) use ($menuItemFormatter) {
                return $menuItemFormatter
                    ->init($item)
                    ->id()
                    ->title()
                    ->position()
                    ->route()
                    ->children()
                    ->pageType()
                    ->highlighted()
                    ->format();
            }, $menuItemService->getAll($id, MenuItemServiceInterface::MENU));
        });

        return $this->json($data, $status);
    }

    /**
     * @Route("/api/menu/{id}/items/{position}", methods={"GET"}, name="api_menu_items_get")
     *
     * @param int $id
     * @param int $position
     * @param MenuItemServiceInterface $menuItemService
     * @param MenuItemFormatterInterface $menuItemFormatter
     * @return Response
     */
    public function getAction(
        int $id,
{'fraction_non_alphanumeric': 0.11535068372298192, 'fraction_numerical': 0.00529333921482135, 'mean_word_length': 2.8497453310696095, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4034442', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1230, 'n_words': 246}