<commit_before><?php

namespace SumoCoders\FrameworkMultiUserBundle\Command;

use SumoCoders\FrameworkMultiUserBundle\Exception\InvalidPasswordConfirmationException;
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;

class PasswordResetHandler
{
    /**
     * @var UserRepositoryCollection
     */
    private $userRepositoryCollection;

    public function __construct(UserRepositoryCollection $userRepositoryCollection)
    {
        $this->userRepositoryCollection = $userRepositoryCollection;
    }

    /**
     * @param ResetPassword $command
     *
     * @throws InvalidPasswordConfirmationException
     */
    public function handle(ResetPassword $command)
    {
        if ($command->passwordConfirmationIsValid()) {
            $user = $command->getUser();
            $updatedUser = clone $user;
            $updatedUser->setPassword($command->getPassword());
            $updatedUser->clearPasswordResetToken();
            $repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user));
            $repository->update($user, $updatedUser);

            return;
        }

        throw new InvalidPasswordConfirmationException('The password confirmation isn\'t valid');
    }
}<commit_msg>Refactor Password resetHandler handle function<commit_after><?php

namespace SumoCoders\FrameworkMultiUserBundle\Command;

use SumoCoders\FrameworkMultiUserBundle\Exception\InvalidPasswordConfirmationException;
use SumoCoders\FrameworkMultiUserBundle\User\UserRepositoryCollection;

class PasswordResetHandler
{
    /**
     * @var UserRepositoryCollection
     */
    private $userRepositoryCollection;

    public function __construct(UserRepositoryCollection $userRepositoryCollection)
    {
        $this->userRepositoryCollection = $userRepositoryCollection;
    }

    /**
     * @param ResetPassword $command
     *
     * @throws InvalidPasswordConfirmationException
     */
    public function handle(ResetPassword $command)
    {
        if (!$command->passwordConfirmationIsValid()) {
            throw new InvalidPasswordConfirmationException('The password confirmation isn\'t valid');
        }
        
        $user = $command->getUser();
        $updatedUser = clone $user;
        $updatedUser->setPassword($command->getPassword());
        $updatedUser->clearPasswordResetToken();
        $repository = $this->userRepositoryCollection->findRepositoryByClassName(get_class($user));
        $repository->update($user, $updatedUser);

        return;
    }
}
{'fraction_non_alphanumeric': 0.09691455696202532, 'fraction_numerical': 0.0, 'mean_word_length': 3.623400365630713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '3929265', 'n_tokens_mistral': 615, 'n_tokens_neox': 606, 'n_words': 102}