<commit_before><?php

namespace TyrSynchroBundle\Service;

use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
use PhpAmqpLib\Message\AMQPMessage;
use Symfony\Component\Security\Core\User\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use ApiBundle\Service\OriginManager;

class TyrEventConsumer implements ConsumerInterface
{
    /**
     * @var UserManagerInterface
     */
    private $userManager;

    /**
     * @var OriginManager
     */
    private $originManager;

    /**
     * @param UserManagerInterface $userManager
     * @param ObjectManager        $om
     */
    public function __construct(UserManagerInterface $userManager, OriginManager $originManager)
    {
        $this->userManager = $userManager;
        $this->originManager = $originManager;
    }

    /**
     * {@inheritdoc}
     *
     * Expected JSON message:
     * {"event": "create_user", "data": {...}}
     */
    public function execute(AMQPMessage $msg)
    {
        $message = json_decode($msg->getBody());

        switch ($message->event) {
            case 'create_user':
                $user = $this->userManager->createUser();
                $this->updateUser($message->data, $user);
                break;
            case 'update_user':
                $user = $this->userManager->findUserByUsername($message->data->username);
                $this->updateUser($message->data, $user);
                break;
            case 'delete_user':
                $user = $this->userManager->findUserByUsername($message->data->username);
                $this->deleteUser($user);
                break;
            default:
                throw new \RuntimeException('Unknown event "'.$message->event.'"');
        }
    }

    /**
     * @param UserInterface $user
     */
    private function updateUser(\stdClass $data, UserInterface $user)
    {
        $origin = $this->originManager->findOrCreateByName($data->origin->name);

        $user
            ->setUsername($data->username)
            ->setEmail($data->email)
            ->setOrigin($origin)<commit_msg>Refs #NAVIO-624 ~ update_user event message updated. last_username field added.<commit_after><?php

namespace TyrSynchroBundle\Service;

use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
use PhpAmqpLib\Message\AMQPMessage;
use Symfony\Component\Security\Core\User\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use ApiBundle\Service\OriginManager;

class TyrEventConsumer implements ConsumerInterface
{
    /**
     * @var UserManagerInterface
     */
    private $userManager;

    /**
     * @var OriginManager
     */
    private $originManager;

    /**
     * @param UserManagerInterface $userManager
     * @param ObjectManager        $om
     */
    public function __construct(UserManagerInterface $userManager, OriginManager $originManager)
    {
        $this->userManager = $userManager;
        $this->originManager = $originManager;
    }

    /**
     * {@inheritdoc}
     *
     * Expected JSON message:
     * {"event": "create_user", "data": {...}}
     */
    public function execute(AMQPMessage $msg)
    {
        $message = json_decode($msg->getBody());

        switch ($message->event) {
            case 'create_user':
                $user = $this->userManager->createUser();
                $this->updateUser($message->data, $user);
                break;
            case 'update_user':
                $user = $this->userManager->findUserByUsername($message->data->last_username);
                $this->updateUser($message->data, $user);
                break;
            case 'delete_user':
                $user = $this->userManager->findUserByUsername($message->data->username);
                $this->deleteUser($user);
                break;
            default:
                throw new \RuntimeException('Unknown event "'.$message->event.'"');
        }
    }

    /**
     * @param UserInterface $user
     */
    private function updateUser(\stdClass $data, UserInterface $user)
    {
        $origin = $this->originManager->findOrCreateByName($data->origin->name);

        $user
            ->setUsername($data->username)
            ->setEmail($data->email)
            ->setOrigin($origin)
{'fraction_non_alphanumeric': 0.13051687514751004, 'fraction_numerical': 0.0007080481472740147, 'mean_word_length': 2.2827265685515106, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 61, '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': '6980535', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1131, 'n_words': 201}