<commit_before><?php
/**
 * /src/App/Command/User/EditUserCommand.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Command\User;

use App\Entity\User;
use App\Entity\UserGroup;
use App\Form\Console\UserData;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class EditUserCommand
 *
 * @category    Console
 * @package     App\Command\User
 * @author      TLe, <NAME> <<EMAIL>>
 */
class EditUserCommand extends Base
{
    /**
     * Name of the console command.
     *
     * @var string
     */
    protected $commandName = 'user:edit';

    /**
     * Description of the console command.
     *
     * @var string
     */
    protected $commandDescription = 'Edit user\'s information.';

    /**
     * Supported command line parameters.
     *
     * @var array
     */
    protected $commandParameters = [
        [
            'name'          => 'username',
            'description'   => 'Username',
        ],
    ];

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // Initialize common console command
        parent::execute($input, $output);

        $userFound = false;

        // Ask user till user accept founded user
        while (!$userFound) {
            // Fetch user and show user information
            $user = $this->getUser(true);

            $userFound = $this->io->confirm('Is this the user who\'s information you want to change?', false);
        }

        /** @var User $user */

        /**
         * Lambda function to extract user group ID values from UserGroup entity
         *
         * @param   UserGroup   $userGroup
         *
         * @return  integer
         */
        $iterator = function(UserGroup $userGroup) {
            return $userGroup->getId();
        };

        // Create new DTO with selected user data
        $dto = new UserData();
        $dto->username = $user->getUsername();
        $dto->firstname = $user->getFirstname();
        $dto->surname = $user->getSurname();
        $dto->email = $user->getEmail();

        // Note this won't work atm, see https://github.com/matthiasnoback/symfony-console-form/issues/16
        //$dto->userGroups = array_map($iterator, $user->getUserGroups()->toArray());

        /** @var UserData $dto */
        $dto = $this->getHelper('form')->interactUsingForm(
            'App\Form\Console\User',
            $this->input,<commit_msg>Refactored user:edit command structure.<commit_after><?php
/**
 * /src/App/Command/User/EditUserCommand.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Command\User;

use App\Entity\User;
use App\Entity\UserGroup;
use App\Form\Console\UserData;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * Class EditUserCommand
 *
 * @category    Console
 * @package     App\Command\User
 * @author      TLe, <NAME> <<EMAIL>>
 */
class EditUserCommand extends Base
{
    /**
     * Name of the console command.
     *
     * @var string
     */
    protected $commandName = 'user:edit';

    /**
     * Description of the console command.
     *
     * @var string
     */
    protected $commandDescription = 'Edit user\'s information.';

    /**
     * Supported command line parameters.
     *
     * @var array
     */
    protected $commandParameters = [
        [
            'name'          => 'username',
            'description'   => 'Username',
        ],
    ];

    /**
     * {@inheritdoc}
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // Initialize common console command
        parent::execute($input, $output);

        $userFound = false;

        // Ask user till user accept founded user
        while (!$userFound) {
            // Fetch user and show user information
            $user = $this->getUser(true);

            $userFound = $this->io->confirm('Is this the user who\'s information you want to change?', false);
        }

        /** @var User $user */

        $dto = $this->getUserDto($user);
        // Note this is just a workaround, see https://github.com/matthiasnoback/symfony-console-form/issues/16
        $dto->userGroups = null;

        /** @var UserData $dto */
        $dto = $this->getHelper('form')->interactUsingForm(
            'App\Form\Console\User',
            $this->input,
{'fraction_non_alphanumeric': 0.1374578177727784, 'fraction_numerical': 0.0008998875140607424, 'mean_word_length': 2.0917941585535464, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 45, 'https://': 2, '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': '3940811', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1264, 'n_words': 303}