<commit_before><?php

namespace BlueBear\BackofficeBundle\Controller;

use BlueBear\BackofficeBundle\Controller\Behavior\ControllerBehavior;
use BlueBear\CoreBundle\Entity\Map\Pencil;
use BlueBear\CoreBundle\Entity\Map\PencilSet;
use BlueBear\CoreBundle\Entity\Map\Tile;
use BlueBear\CoreBundle\Manager\MapManager;
use BlueBear\EngineBundle\Event\EngineEvent;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use stdClass;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ApiController extends Controller
{
    use ControllerBehavior;

    /**
     * @Template()
     */
    public function indexAction()
    {
        $form = $this->createForm('engine_event_test');
        $snippets = $this->getJsonSnippets();

        return [
            'form' => $form->createView(),
            'snippets' => $snippets
        ];
    }

    /**
     * @return string
     */
    protected function getJsonSnippets()
    {
        $events = EngineEvent::getAllowedEvents();
        $map = $this->getMapManager()->findOne();
        $snippets = [];

        foreach ($events as $event) {
            $snippet = new stdClass();
            if ($event == EngineEvent::ENGINE_ON_MAP_LOAD) {
                $snippet->mapId = $map->getId();
                $snippet->contextId = null;
                $snippets[$event] = $snippet;
            } else if ($event == EngineEvent::ENGINE_ON_MAP_SAVE) {
                $snippet->mapId = $map->getId();
                $snippet->context = new stdClass();

                if ($map->getCurrentContext()) {
                    $snippet->context->id = $map->getCurrentContext()->getId();
                    $snippet->context->tiles = [];
                    $tiles[] = $map->getCurrentContext()->getTiles()[0];
                    $tiles[] = $map->getCurrentContext()->getTiles()[1];

                    // get allowed pencils
                    $pencils = [];
                    $pencilSets = $map->getPencilSets();

                    /** @var PencilSet $pencilSet */
                    foreach ($pencilSets as $pencilSet) {
                        $pencils[] = $pencilSet->getPencils();
                    }
                    if (count($pencils)) {
                        /** @var Pencil $pencil */
                        $pencil = $pencils[0];<commit_msg>api test controller improvement<commit_after><?php

namespace BlueBear\BackofficeBundle\Controller;

use BlueBear\BackofficeBundle\Controller\Behavior\ControllerBehavior;
use BlueBear\CoreBundle\Entity\Map\Pencil;
use BlueBear\CoreBundle\Entity\Map\PencilSet;
use BlueBear\CoreBundle\Entity\Map\Tile;
use BlueBear\CoreBundle\Manager\MapManager;
use BlueBear\EngineBundle\Event\EngineEvent;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use stdClass;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class ApiController extends Controller
{
    use ControllerBehavior;

    /**
     * @Template()
     */
    public function indexAction()
    {
        $form = $this->createForm('engine_event_test');
        $snippets = $this->getJsonSnippets();

        return [
            'form' => $form->createView(),
            'snippets' => $snippets
        ];
    }

    /**
     * @return string
     */
    protected function getJsonSnippets()
    {
        $events = EngineEvent::getAllowedEvents();
        $map = $this->getMapManager()->findOne();
        $snippets = [];

        foreach ($events as $event) {
            $snippet = new stdClass();
            if ($event == EngineEvent::ENGINE_ON_MAP_LOAD) {
                $snippet->mapId = $map->getId();
                $snippet->contextId = null;
                $snippets[$event] = $snippet;
            } else if ($event == EngineEvent::ENGINE_ON_MAP_SAVE) {
                $snippet->mapId = $map->getId();
                $snippet->context = new stdClass();

                if ($map->getCurrentContext()) {
                    $snippet->context->id = $map->getCurrentContext()->getId();
                    $snippet->context->tiles = [];
                    $tiles[] = $map->getCurrentContext()->getTiles()[0];
                    $tiles[] = $map->getCurrentContext()->getTiles()[1];

                    // get allowed pencils
                    $pencils = [];
                    $pencilSets = $map->getPencilSets();

                    /** @var PencilSet $pencilSet */
                    foreach ($pencilSets as $pencilSet) {
                        $pencils = array_merge($pencils, $pencilSet->getPencils()->toArray());
                    }
                    if (count($pencils)) {
                        /** @var Pencil $pencil */
                        $pencil = $pencils[0];
{'fraction_non_alphanumeric': 0.13732993197278912, 'fraction_numerical': 0.0012755102040816326, 'mean_word_length': 1.944305381727159, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, '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': '1215369', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1285, 'n_words': 215}