Skip to content

Commit

Permalink
chore: remove deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Jan 14, 2025
1 parent 240b39c commit 12b4b98
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 68 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"suggest": {
"doctrine/doctrine-bundle": "To connect with Doctrine in Symfony project",
"doctrine/orm": "To connect with Doctrine",
"api-platform/core": "To connect with API Platform"
"api-platform/openapi": "To connect with API Platform"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 0 additions & 2 deletions config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
<service id="coop_tilleuls_forgot_password.manager.forgot_password" class="CoopTilleuls\ForgotPasswordBundle\Manager\ForgotPasswordManager" public="true">
<argument type="service" id="coop_tilleuls_forgot_password.manager.password_token" />
<argument type="service" id="event_dispatcher" />
<argument type="service" id="coop_tilleuls_forgot_password.provider_chain"/>
</service>

<service id="coop_tilleuls_forgot_password.manager.password_token" class="CoopTilleuls\ForgotPasswordBundle\Manager\PasswordTokenManager" public="true">
<argument type="service" id="coop_tilleuls_forgot_password.provider_chain"/>
<argument/> <!-- token_generator -->
</service>

Expand Down
17 changes: 0 additions & 17 deletions src/DependencyInjection/BCExtensionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,6 @@ public function load(array $configs, ContainerBuilder $container): void
throw new InvalidConfigurationException('Multiple "ForgotPassword" providers have been defined but none of them is set as default. Did you forget to set "default" option?');
}

// Build parameters
$container->setParameter('coop_tilleuls_forgot_password.password_token_class', $defaultProvider['password_token']['class']);
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_class');
$container->setParameter('coop_tilleuls_forgot_password.password_token_expires_in', $defaultProvider['password_token']['expires_in']);
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_expires_in');
$container->setParameter('coop_tilleuls_forgot_password.password_token_user_field', $defaultProvider['password_token']['user_field']);
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_user_field');
$container->setParameter('coop_tilleuls_forgot_password.password_token_serialization_groups', $defaultProvider['password_token']['serialization_groups']);
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.password_token_serialization_groups');
$container->setParameter('coop_tilleuls_forgot_password.user_class', $defaultProvider['user']['class']);
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_class');
$authorizedFields = array_unique(array_merge($defaultProvider['user']['authorized_fields'], [$defaultProvider['user']['email_field']]));
$container->setParameter('coop_tilleuls_forgot_password.user_authorized_fields', $authorizedFields);
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_authorized_fields');
$container->setParameter('coop_tilleuls_forgot_password.user_password_field', $defaultProvider['user']['password_field']);
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Container parameter "%s" is deprecated since 1.5 and will be removed without replacement in 2.0.', 'coop_tilleuls_forgot_password.user_password_field');

$this->buildProvider($config, $container);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
Expand Down
3 changes: 1 addition & 2 deletions src/Exception/MissingFieldHttpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ final class MissingFieldHttpException extends HttpException implements JsonHttpE
{
public function __construct($fieldName)
{
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Status code will change to "%s" in 2.0.', 422);
parent::__construct(400, \sprintf('Parameter "%s" is missing.', $fieldName));
parent::__construct(422, \sprintf('Parameter "%s" is missing.', $fieldName));
}
}
20 changes: 3 additions & 17 deletions src/Manager/ForgotPasswordManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
use CoopTilleuls\ForgotPasswordBundle\Event\ForgotPasswordEvent;
use CoopTilleuls\ForgotPasswordBundle\Event\UpdatePasswordEvent;
use CoopTilleuls\ForgotPasswordBundle\Event\UserNotFoundEvent;
use CoopTilleuls\ForgotPasswordBundle\Provider\Provider;
use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface;
use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
Expand All @@ -29,18 +27,12 @@
*/
class ForgotPasswordManager
{
public function __construct(private readonly PasswordTokenManager $passwordTokenManager, private readonly EventDispatcherInterface $dispatcher, private readonly ProviderChainInterface $providerChain)
public function __construct(private readonly PasswordTokenManager $passwordTokenManager, private readonly EventDispatcherInterface $dispatcher)
{
}

public function resetPassword($propertyName, $value, ?ProviderInterface $provider = null): void
public function resetPassword($propertyName, $value, ProviderInterface $provider): void
{
/* @var null|Provider $provider */
if (!$provider) {
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__);
$provider = $this->providerChain->get();
}

$context = [$propertyName => $value];

$user = $provider->getManager()->findOneBy($provider->getUserClass(), $context);
Expand Down Expand Up @@ -78,14 +70,8 @@ public function resetPassword($propertyName, $value, ?ProviderInterface $provide
*
* @return bool
*/
public function updatePassword(AbstractPasswordToken $passwordToken, $password, ?ProviderInterface $provider = null)
public function updatePassword(AbstractPasswordToken $passwordToken, $password, ProviderInterface $provider)
{
/* @var null|Provider $provider */
if (!$provider) {
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__);
$provider = $this->providerChain->get();
}

// Update user password
if ($this->dispatcher instanceof ContractsEventDispatcherInterface) {
$this->dispatcher->dispatch(new UpdatePasswordEvent($passwordToken, $password));
Expand Down
28 changes: 4 additions & 24 deletions src/Manager/PasswordTokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
namespace CoopTilleuls\ForgotPasswordBundle\Manager;

use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken;
use CoopTilleuls\ForgotPasswordBundle\Provider\Provider;
use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface;
use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderInterface;
use CoopTilleuls\ForgotPasswordBundle\TokenGenerator\TokenGeneratorInterface;

Expand All @@ -24,21 +22,15 @@
*/
class PasswordTokenManager
{
public function __construct(private readonly ProviderChainInterface $providerChain, private readonly TokenGeneratorInterface $tokenGenerator)
public function __construct(private readonly TokenGeneratorInterface $tokenGenerator)
{
}

/**
* @return AbstractPasswordToken
*/
public function createPasswordToken($user, ?\DateTime $expiresAt = null, ?ProviderInterface $provider = null)
public function createPasswordToken($user, ?\DateTime $expiresAt = null, ProviderInterface $provider)
{
/* @var Provider $provider */
if (!$provider) {
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__);
$provider = $this->providerChain->get();
}

if (!$expiresAt) {
$expiresAt = new \DateTime($provider->getPasswordTokenExpiredIn());
$expiresAt->setTime((int) $expiresAt->format('H'), (int) $expiresAt->format('i'), (int) $expiresAt->format('s'), 0);
Expand All @@ -61,28 +53,16 @@ public function createPasswordToken($user, ?\DateTime $expiresAt = null, ?Provid
*
* @return AbstractPasswordToken
*/
public function findOneByToken($token, ?ProviderInterface $provider = null)
public function findOneByToken($token, ProviderInterface $provider)
{
/* @var null|Provider $provider */
if (!$provider) {
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__);
$provider = $this->providerChain->get();
}

return $provider->getManager()->findOneBy($provider->getPasswordTokenClass(), ['token' => $token]);
}

/**
* @return AbstractPasswordToken
*/
public function findOneByUser($user, ?ProviderInterface $provider = null)
public function findOneByUser($user, ProviderInterface $provider)
{
/* @var null|Provider $provider */
if (!$provider) {
trigger_deprecation('tilleuls/forgot-password-bundle', '1.5', 'Parameter "%s" in method "%s" is recommended since 1.5 and will be mandatory in 2.0.', '$provider', __METHOD__);
$provider = $this->providerChain->get();
}

return $provider->getManager()->findOneBy($provider->getPasswordTokenClass(), [$provider->getPasswordTokenUserField() => $user]);
}
}
2 changes: 1 addition & 1 deletion tests/EventListener/ExceptionEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testOnKernelException(): void
['message' => 'Parameter "foo" is missing.'],
15
) === $response->getContent()
&& 400 === $response->getStatusCode()));
&& 422 === $response->getStatusCode()));

$listener = new ExceptionEventListener();
$listener->onKernelException($eventMock);
Expand Down
5 changes: 1 addition & 4 deletions tests/Manager/PasswordTokenManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use CoopTilleuls\ForgotPasswordBundle\Entity\AbstractPasswordToken;
use CoopTilleuls\ForgotPasswordBundle\Manager\Bridge\ManagerInterface;
use CoopTilleuls\ForgotPasswordBundle\Manager\PasswordTokenManager;
use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderChainInterface;
use CoopTilleuls\ForgotPasswordBundle\Provider\ProviderInterface;
use CoopTilleuls\ForgotPasswordBundle\TokenGenerator\TokenGeneratorInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -34,7 +33,6 @@ final class PasswordTokenManagerTest extends TestCase
private $managerMock;
private $userMock;
private $tokenMock;
private $providerChainMock;
private $providerMock;
private $tokenGeneratorMock;

Expand All @@ -43,11 +41,10 @@ protected function setUp(): void
$this->managerMock = $this->createMock(ManagerInterface::class);
$this->userMock = $this->createMock(UserInterface::class);
$this->tokenMock = $this->createMock(AbstractPasswordToken::class);
$this->providerChainMock = $this->createMock(ProviderChainInterface::class);
$this->providerMock = $this->createMock(ProviderInterface::class);
$this->tokenGeneratorMock = $this->createMock(TokenGeneratorInterface::class);

$this->manager = new PasswordTokenManager($this->providerChainMock, $this->tokenGeneratorMock);
$this->manager = new PasswordTokenManager($this->tokenGeneratorMock);
}

public function testCreatePasswordToken(): void
Expand Down

0 comments on commit 12b4b98

Please sign in to comment.