<commit_before><?php

/*
 * This file is part of the Sylius package.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Sylius\Bundle\UserBundle\Security;

use Sylius\Component\User\Model\CredentialsHolderInterface;
use Sylius\Component\User\Security\UserPasswordHasherInterface;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;

final class UserPasswordHasher implements UserPasswordHasherInterface
{
    public function __construct(private PasswordHasherFactoryInterface $passwordHasherFactory)
    {
    }

    public function hash(CredentialsHolderInterface $user): string
    {
        /** @psalm-suppress InvalidArgument */
        $passwordHasher = $this->passwordHasherFactory->getPasswordHasher($user::class);

        return $passwordHasher->hash($user->getPlainPassword());
    }
}<commit_msg>[PHPStan] Fix Password Hasher (#14019)<commit_after><?php

/*
 * This file is part of the Sylius package.
 *
 * (c) <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

declare(strict_types=1);

namespace Sylius\Bundle\UserBundle\Security;

use Sylius\Component\User\Model\CredentialsHolderInterface;
use Sylius\Component\User\Security\UserPasswordHasherInterface;
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
use Symfony\Component\PasswordHasher\LegacyPasswordHasherInterface;
use Webmozart\Assert\Assert;

final class UserPasswordHasher implements UserPasswordHasherInterface
{
    public function __construct(private PasswordHasherFactoryInterface $passwordHasherFactory)
    {
    }

    public function hash(CredentialsHolderInterface $user): string
    {
        /** @psalm-suppress InvalidArgument */
        $passwordHasher = $this->passwordHasherFactory->getPasswordHasher($user::class);
        Assert::isInstanceOf($passwordHasher, LegacyPasswordHasherInterface::class);

        return $passwordHasher->hash($user->getPlainPassword());
    }
}
{'fraction_non_alphanumeric': 0.09286047596826878, 'fraction_numerical': 0.0032664489034064394, 'mean_word_length': 5.090909090909091, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '2367837', 'n_tokens_mistral': 593, 'n_tokens_neox': 579, 'n_words': 130}