<commit_before><?php

namespace AppBundle\Controller;

use AppBundle\Model\SelfRegisterData;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use \Doctrine\Common\Util\Debug as doctrineDebug;

/**
 * @Route("/selfregister")
 */
class SelfRegisterController extends RestController
{
    /**
     * @Route("")
     * @Method({"POST"})
     */
    public function register(Request $request)
    {
        if (!$this->getAuthService()->isSecretValid($request)) {
            throw new \RuntimeException('client secret not accepted.', 403);
        }

        $data = $this->deserializeBodyContent($request);

        $selfRegisterData = new SelfRegisterData();

        $this->populateSelfReg($selfRegisterData, $data);

        $validator = $this->get('validator');
        $errors = $validator->validate($selfRegisterData, 'self_registration');

        if (count($errors) > 0) {
            throw new \RuntimeException('Invalid registration data: ' . $errors);
        }

        try {
            $user = $this->container->get('user_registration_service')->selfRegisterUser($selfRegisterData);
            $this->get('logger')->warning('CasRec register success: ', ['extra' => ['page' => 'user_registration', 'success' => true] + $selfRegisterData->toArray()]);
        } catch (\Exception $e) {
            $this->get('logger')->warning('CasRec register failed:', ['extra' => ['page' => 'user_registration', 'success' => false] + $selfRegisterData->toArray()]);
            throw $e;
        }

        $this->setJmsSerialiserGroups(['user', 'user-login']);

        return $user;
    }


    /**
     * @Route("/verifycodeputy")
     * @Method({"POST"})
     */
    public function verifyCoDeputy(Request $request)
    {
        $coDeputyVerified = false;

        if (!$this->getAuthService()->isSecretValid($request)) {
            throw new \RuntimeException('client secret not accepted.', 403);
        }

        $selfRegisterData = new SelfRegisterData();
        $this->populateSelfReg($selfRegisterData, $this->deserializeBodyContent($request));

        $validator = $this->get('validator');
        $errors = $validator->validate($selfRegisterData, ['verify_codeputy']);

        if (count($errors) > 0) {
            throw new \RuntimeException('Invalid registration data: ' . $errors);
        }

        try {
            $coDeputyVerified = $this->container->get('user_registration_service')->validateCoDeputy($selfRegisterData);
            $this->get('logger')->warning('CasRec codeputy validation success: ', ['extra' => ['page' => 'codep_validation', 'success' => true] + $selfRegisterData->toArray()]);
        } catch (\Exception $e) {
            $this->get('logger')->warning('CasRec codeputy validation failed:', ['extra' => ['page' => 'codep_validation', 'success' => false] + $selfRegisterData->toArray()]);
throw $e;
        }

return print_r(doctrineDebug::export($coDeputyVerified, 3),true);

        return ['verified' => $coDeputyVerified];
    }

    /*
     * @param SelfRegisterData $selfRegisterData
     * @param array $data
     */
    public function populateSelfReg(SelfRegisterData $selfRegisterData, array $data)
    {
        $this->hydrateEntityWithArrayData($selfRegisterData, $data, [
            'firstname' => 'setFirstname',
            'lastname' => 'setLastname',
            'email' => 'setEmail',
            'postcode' => 'setPostcode',
            'client_firstname' => 'setClientFirstname',
            'client_lastname' => 'setClientLastname',
            'case_number' => 'setCaseNumber',
        ]);
    }
}<commit_msg>EPIC-co-deputies Remove debug left in<commit_after><?php

namespace AppBundle\Controller;

use AppBundle\Model\SelfRegisterData;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use \Doctrine\Common\Util\Debug as doctrineDebug;

/**
 * @Route("/selfregister")
 */
class SelfRegisterController extends RestController
{
    /**
     * @Route("")
     * @Method({"POST"})
     */
    public function register(Request $request)
    {
        if (!$this->getAuthService()->isSecretValid($request)) {
            throw new \RuntimeException('client secret not accepted.', 403);
        }

        $data = $this->deserializeBodyContent($request);

        $selfRegisterData = new SelfRegisterData();

        $this->populateSelfReg($selfRegisterData, $data);

        $validator = $this->get('validator');
        $errors = $validator->validate($selfRegisterData, 'self_registration');

        if (count($errors) > 0) {
            throw new \RuntimeException('Invalid registration data: ' . $errors);
        }

        try {
            $user = $this->container->get('user_registration_service')->selfRegisterUser($selfRegisterData);
            $this->get('logger')->warning('CasRec register success: ', ['extra' => ['page' => 'user_registration', 'success' => true] + $selfRegisterData->toArray()]);
        } catch (\Exception $e) {
            $this->get('logger')->warning('CasRec register failed:', ['extra' => ['page' => 'user_registration', 'success' => false] + $selfRegisterData->toArray()]);
            throw $e;
        }

        $this->setJmsSerialiserGroups(['user', 'user-login']);

        return $user;
    }


    /**
     * @Route("/verifycodeputy")
     * @Method({"POST"})
     */
    public function verifyCoDeputy(Request $request)
    {
        $coDeputyVerified = false;

        if (!$this->getAuthService()->isSecretValid($request)) {
            throw new \RuntimeException('client secret not accepted.', 403);
        }

        $selfRegisterData = new SelfRegisterData();
        $this->populateSelfReg($selfRegisterData, $this->deserializeBodyContent($request));

        $validator = $this->get('validator');
        $errors = $validator->validate($selfRegisterData, ['verify_codeputy']);

        if (count($errors) > 0) {
            throw new \RuntimeException('Invalid registration data: ' . $errors);
        }

        try {
            $coDeputyVerified = $this->container->get('user_registration_service')->validateCoDeputy($selfRegisterData);
            $this->get('logger')->warning('CasRec codeputy validation success: ', ['extra' => ['page' => 'codep_validation', 'success' => true] + $selfRegisterData->toArray()]);
        } catch (\Exception $e) {
            $this->get('logger')->warning('CasRec codeputy validation failed:', ['extra' => ['page' => 'codep_validation', 'success' => false] + $selfRegisterData->toArray()]);
            throw $e;
        }

        return ['verified' => $coDeputyVerified];
    }

    /*
     * @param SelfRegisterData $selfRegisterData
     * @param array $data
     */
    public function populateSelfReg(SelfRegisterData $selfRegisterData, array $data)
    {
        $this->hydrateEntityWithArrayData($selfRegisterData, $data, [
            'firstname' => 'setFirstname',
            'lastname' => 'setLastname',
            'email' => 'setEmail',
            'postcode' => 'setPostcode',
            'client_firstname' => 'setClientFirstname',
            'client_lastname' => 'setClientLastname',
            'case_number' => 'setCaseNumber',
        ]);
    }
}
{'fraction_non_alphanumeric': 0.16003260426572477, 'fraction_numerical': 0.0023094688221709007, 'mean_word_length': 3.0517336268574575, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 111, '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': '7053819', 'n_tokens_mistral': 2075, 'n_tokens_neox': 2017, 'n_words': 369}