<commit_before><?php

namespace AppBundle\Character;

use AppBundle\Entity\Character;
use AppBundle\Entity\Event;
use AppBundle\Entity\Repository\EventRepository;
use AppBundle\Entity\Repository\SceneRepository;
use Symfony\Component\Templating\EngineInterface;

class TimelineFormatter
{
    /**
     * @var SceneRepository
     */
    private $sceneRepository;

    /**
     * @var EventRepository
     */
    private $eventRepository;

    /**
     * @var EngineInterface
     */
    private $templating;

    public function __construct(
        SceneRepository $sceneRepository,
        EventRepository $eventRepository,
        EngineInterface $templating
    ) {
        $this->sceneRepository = $sceneRepository;
        $this->eventRepository = $eventRepository;
        $this->templating = $templating;
    }

    public function getTimeline(Character $character)
    {
        $creation = $this->sceneRepository->firstCharacterOccurence($character);

        return array_merge(
            ['character.timeline.creation' => ['fa fa-user-plus' => $creation]],
            $this->formatEvents($this->eventRepository->findForCharacter($character))
        );
    }

    /**
     * @param Event[] $events
     */
    private function formatEvents(array $events)
    {
        return array_reduce($events, function (array $initial, Event $event) {
            $model = $event->getModel();
            $fqcn = explode('\\', get_class($model));
            $template = sprintf(
                'scene/events/%s.html.twig',
                mb_strtolower(end($fqcn))
            );
            $label = sprintf('event.%s.name', get_class($model));
            $initial[$label] = [
                'fa fa-users' => $this->templating->render($template, ['model' => $model])
            ];

            return $initial;
        }, []);
    }
}<commit_msg>Assign unique icon to event in character timeline formatter<commit_after><?php

namespace AppBundle\Character;

use AppBundle\Entity\Character;
use AppBundle\Entity\Event;
use AppBundle\Entity\Repository\EventRepository;
use AppBundle\Entity\Repository\SceneRepository;
use AppBundle\Model\Meeting;
use Symfony\Component\Templating\EngineInterface;
use function mb_strtolower;

class TimelineFormatter
{
    /**
     * @var SceneRepository
     */
    private $sceneRepository;

    /**
     * @var EventRepository
     */
    private $eventRepository;

    /**
     * @var EngineInterface
     */
    private $templating;

    /**
     * @var array
     */
    private $icons = [
        Meeting::class => 'fa fa-users'
    ];

    public function __construct(
        SceneRepository $sceneRepository,
        EventRepository $eventRepository,
        EngineInterface $templating
    ) {
        $this->sceneRepository = $sceneRepository;
        $this->eventRepository = $eventRepository;
        $this->templating = $templating;
    }

    public function getTimeline(Character $character)
    {
        $creation = $this->sceneRepository->firstCharacterOccurence($character);

        return array_merge(
            ['character.timeline.creation' => ['fa fa-user-plus' => $creation]],
            $this->formatEvents($this->eventRepository->findForCharacter($character))
        );
    }

    /**
     * @param Event[] $events
     */
    private function formatEvents(array $events)
    {
        return array_reduce($events, function (array $initial, Event $event) {
            $model = $event->getModel();
            $modelClass = get_class($model);
            $fqcn = explode('\\', $modelClass);
            $template = sprintf('scene/events/%s.html.twig', mb_strtolower(end($fqcn)));
            $initial[sprintf('event.%s.name', $modelClass)] = [
                $this->icons[$modelClass] => $this->templating->render($template, ['model' => $model])
            ];

            return $initial;
        }, []);
    }
}
{'fraction_non_alphanumeric': 0.13220164609053497, 'fraction_numerical': 0.0, 'mean_word_length': 2.5130984643179763, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '4033674', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1058, 'n_words': 196}