<commit_before><?php

namespace App\Action;

use App\Repository\SpeakersRepository;
use Slim\Views\Twig;
use Psr\Log\LoggerInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use App\Model\Event\Speaker;

final class CreateSpeakerAction
{

    /**
     * @var Twig
     */
    private $view;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @var SpeakersRepository
     */
    private $speakersRepository;

    public function __construct(Twig $view, LoggerInterface $logger, SpeakersRepository $speakersRepository)
    {
        $this->view = $view;
        $this->logger = $logger;
        $this->speakersRepository = $speakersRepository;
    }

    public function dispatch(Request $request, Response $response, $args)
    {
        if($request->isPost()) {
            $speaker = new Speaker(
                $request->getParam('first_name'),
                $request->getParam('last_name'),
                $request->getParam('email'),
                $request->getParam('twitter')
            );

            $msg = [];
            try {
                $this->speakersRepository->save($speaker);
                $msg['id'] = $speaker->id;
            } catch (\Exception $e) {
                return $response->withStatus(200)
                    ->withHeader('Content-Type', 'application/json')
                    ->write(json_encode(['error' => $e->getMessage()]));
            }
<commit_msg>Updated to include value objects.<commit_after><?php

namespace App\Action;

use App\Model\Email;
use App\Model\Twitter;
use App\Repository\SpeakersRepository;
use Slim\Views\Twig;
use Psr\Log\LoggerInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use App\Model\Event\Entity\Speaker;

final class CreateSpeakerAction
{

    /**
     * @var Twig
     */
    private $view;

    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @var SpeakersRepository
     */
    private $speakersRepository;

    public function __construct(Twig $view, LoggerInterface $logger, SpeakersRepository $speakersRepository)
    {
        $this->view = $view;
        $this->logger = $logger;
        $this->speakersRepository = $speakersRepository;
    }

    public function dispatch(Request $request, Response $response, $args)
    {
        if($request->isPost()) {
            $speaker = new Speaker(
                null,
                $request->getParam('first_name'),
                $request->getParam('last_name'),
                new Email($request->getParam('email')),
                new Twitter($request->getParam('twitter'))
            );

            $msg = [];
            try {
                $this->speakersRepository->save($speaker);
                $msg['id'] = $speaker->id;
            } catch (\Exception $e) {
                return $response->withStatus(200)
                    ->withHeader('Content-Type', 'application/json')
                    ->write(json_encode(['error' => $e->getMessage()]));
            }

{'fraction_non_alphanumeric': 0.13704568189396465, 'fraction_numerical': 0.0020006668889629878, 'mean_word_length': 2.0364372469635628, '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': '1067036', 'n_tokens_mistral': 856, 'n_tokens_neox': 821, 'n_words': 157}