Skip to content

Commit

Permalink
chore: upgrade code to PHP 8.1 (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed May 23, 2024
1 parent 84dd8d4 commit 802f703
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 231 deletions.
14 changes: 1 addition & 13 deletions features/app/src/EventListener/ForgotPasswordEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,13 @@
*/
final class ForgotPasswordEventListener implements EventSubscriberInterface
{
/**
* @var MailerInterface
*/
private $mailer;

/**
* @var EngineInterface|Environment
*/
private $twig;

/**
* @var EntityManagerInterface
*/
private $entityManager;

public function __construct(MailerInterface $mailer, $twig, Registry $doctrine)
public function __construct(private readonly MailerInterface $mailer, private readonly EngineInterface|Environment $twig, Registry $doctrine)
{
$this->mailer = $mailer;
$this->twig = $twig;
$this->entityManager = $doctrine->getManager();
}

Expand Down
30 changes: 3 additions & 27 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@
*/
final class FeatureContext implements Context
{
/**
* @var Registry
*/
private $doctrine;

/**
* @var Client|KernelBrowser
*/
private $client;

/**
* @var PasswordTokenManager
*/
private $passwordTokenManager;

/**
* @var Application
*/
Expand All @@ -60,19 +45,10 @@ final class FeatureContext implements Context
*/
private $output;

/**
* @var ProviderChainInterface
*/
private $providerChain;

public function __construct($client, Registry $doctrine, PasswordTokenManager $passwordTokenManager, ProviderChainInterface $providerChain, KernelInterface $kernel)
public function __construct(private readonly Client|KernelBrowser $client, private readonly Registry $doctrine, private readonly PasswordTokenManager $passwordTokenManager, private readonly ProviderChainInterface $providerChain, KernelInterface $kernel)
{
$this->client = $client;
$this->doctrine = $doctrine;
$this->passwordTokenManager = $passwordTokenManager;
$this->application = new Application($kernel);
$this->output = new BufferedOutput();
$this->providerChain = $providerChain;
}

/**
Expand All @@ -84,7 +60,7 @@ public function resetDatabase(): void
$purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
try {
$purger->purge();
} catch (Exception $e) {
} catch (Exception) {
$schemaTool = new SchemaTool($this->doctrine->getManager());
$schemaTool->createSchema($this->doctrine->getManager()->getMetadataFactory()->getAllMetadata());
}
Expand Down Expand Up @@ -408,7 +384,7 @@ public function iShouldGetAnOpenApiDocumentationUpdated(): void
{
$output = $this->output->fetch();
Assert::assertJson($output);
$openApi = json_decode($output, true);
$openApi = json_decode((string) $output, true);
Assert::assertEquals($this->getOpenApiPaths(), $openApi['paths']);
Assert::assertEquals([
'schemas' => [
Expand Down
28 changes: 28 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the CoopTilleulsForgotPasswordBundle package.
*
* (c) Vincent CHALAMON <vincent@les-tilleuls.coop>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__DIR__.'/features',
__DIR__.'/src',
__DIR__.'/tests',
])
// uncomment to reach your current PHP version
// ->withPhpSets()
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
])
->withPhpSets(php81: true);
12 changes: 1 addition & 11 deletions src/Bridge/ApiPlatform/OpenApi/AbstractOpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,8 @@
*/
abstract class AbstractOpenApiFactory
{
protected $decorated;
protected $router;
protected $providerChain;

/**
* @param LegacyOpenApiFactoryInterface|OpenApiFactoryInterface $decorated
*/
public function __construct($decorated, RouterInterface $router, ProviderChainInterface $providerChain)
public function __construct(protected readonly LegacyOpenApiFactoryInterface|OpenApiFactoryInterface $decorated, protected readonly RouterInterface $router, protected readonly ProviderChainInterface $providerChain)
{
$this->providerChain = $providerChain;
$this->decorated = $decorated;
$this->router = $router;
}

public function __invoke(array $context = [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,8 @@
*/
final class DocumentationNormalizer implements NormalizerInterface
{
private $decorated;
private $router;
private $providerChain;

public function __construct(NormalizerInterface $decorated, RouterInterface $router, ProviderChainInterface $providerChain)
public function __construct(private readonly NormalizerInterface $decorated, private readonly RouterInterface $router, private readonly ProviderChainInterface $providerChain)
{
$this->decorated = $decorated;
$this->router = $router;
$this->providerChain = $providerChain;
}

public function normalize($object, $format = null, array $context = []): array
Expand Down
9 changes: 1 addition & 8 deletions src/Controller/ForgotPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,8 @@
*/
final class ForgotPasswordController
{
private $getToken;
private $updatePassword;
private $resetPassword;

public function __construct(GetToken $getToken, UpdatePassword $updatePassword, ResetPassword $resetPassword)
public function __construct(private readonly GetToken $getToken, private readonly UpdatePassword $updatePassword, private readonly ResetPassword $resetPassword)
{
$this->getToken = $getToken;
$this->updatePassword = $updatePassword;
$this->resetPassword = $resetPassword;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Controller/GetToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
*/
final class GetToken
{
private $normalizer;

public function __construct(NormalizerInterface $normalizer)
public function __construct(private readonly NormalizerInterface $normalizer)
{
$this->normalizer = $normalizer;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Controller/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
*/
final class ResetPassword
{
private $forgotPasswordManager;

public function __construct(ForgotPasswordManager $forgotPasswordManager)
public function __construct(private readonly ForgotPasswordManager $forgotPasswordManager)
{
$this->forgotPasswordManager = $forgotPasswordManager;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Controller/UpdatePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
*/
final class UpdatePassword
{
private $forgotPasswordManager;

public function __construct(ForgotPasswordManager $forgotPasswordManager)
public function __construct(private readonly ForgotPasswordManager $forgotPasswordManager)
{
$this->forgotPasswordManager = $forgotPasswordManager;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode
->beforeNormalization()
->ifTrue(function ($config) {
return \array_key_exists('password_token_class', $config) || \array_key_exists('user_class', $config);
})
->ifTrue(fn ($config) => \array_key_exists('password_token_class', $config) || \array_key_exists('user_class', $config))
->then(function ($config) {
if (\array_key_exists('password_token_class', $config)) {
if (!isset($config['password_token'])) {
Expand All @@ -54,9 +52,7 @@ public function getConfigTreeBuilder(): TreeBuilder

return $config;
})
->ifTrue(function ($config) {
return !\array_key_exists('providers', $config);
})
->ifTrue(fn ($config) => !\array_key_exists('providers', $config))
->then(function ($config) {
$config['providers']['default']['default'] = true;
$config['providers']['default']['password_token'] = $config['password_token'];
Expand Down
10 changes: 1 addition & 9 deletions src/Event/ForgotPasswordEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@ class ForgotPasswordEvent extends PolyfillEvent
public const CREATE_TOKEN = 'coop_tilleuls_forgot_password.create_token';
public const UPDATE_PASSWORD = 'coop_tilleuls_forgot_password.update_password';

protected $passwordToken;
protected $password;

/**
* @param string $password
*/
public function __construct(AbstractPasswordToken $passwordToken, $password = null)
public function __construct(protected readonly AbstractPasswordToken $passwordToken, protected readonly ?string $password = null)
{
$this->passwordToken = $passwordToken;
$this->password = $password;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Event/UserNotFoundEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ final class UserNotFoundEvent extends PolyfillEvent
{
public const USER_NOT_FOUND = 'coop_tilleuls_forgot_password.user_not_found';

private array $context;

public function __construct(array $context = [])
public function __construct(private readonly array $context = [])
{
$this->context = $context;
}

/**
Expand Down
11 changes: 2 additions & 9 deletions src/EventListener/RequestEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ final class RequestEventListener
{
use MainRequestTrait;

private $passwordTokenManager;
private ProviderChainInterface $providerChain;

public function __construct(
PasswordTokenManager $passwordTokenManager,
ProviderChainInterface $providerChain
) {
$this->passwordTokenManager = $passwordTokenManager;
$this->providerChain = $providerChain;
public function __construct(private readonly PasswordTokenManager $passwordTokenManager, private readonly ProviderChainInterface $providerChain)
{
}

public function decodeRequest(KernelEvent $event): void
Expand Down
11 changes: 4 additions & 7 deletions src/Manager/Bridge/DoctrineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@

namespace CoopTilleuls\ForgotPasswordBundle\Manager\Bridge;

use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
use Doctrine\Persistence\ManagerRegistry;

/**
* @author Vincent CHALAMON <vincent@les-tilleuls.coop>
*/
final class DoctrineManager implements ManagerInterface
{
private $registry;

/**
* @var \Doctrine\Common\Persistence\ManagerRegistry|\Doctrine\Persistence\ManagerRegistry
*/
public function __construct($registry)
public function __construct(private readonly LegacyManagerRegistry|ManagerRegistry $registry)
{
$this->registry = $registry;
}

public function findOneBy($class, array $criteria)
Expand Down
14 changes: 2 additions & 12 deletions src/Manager/ForgotPasswordManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,8 @@
*/
class ForgotPasswordManager
{
private $passwordTokenManager;
private $dispatcher;
private $providerChain;

public function __construct(
PasswordTokenManager $passwordTokenManager,
EventDispatcherInterface $dispatcher,
ProviderChainInterface $providerChain
) {
$this->passwordTokenManager = $passwordTokenManager;
$this->dispatcher = $dispatcher;
$this->providerChain = $providerChain;
public function __construct(private readonly PasswordTokenManager $passwordTokenManager, private readonly EventDispatcherInterface $dispatcher, private readonly ProviderChainInterface $providerChain)
{
}

public function resetPassword($propertyName, $value, ?ProviderInterface $provider = null): void
Expand Down
5 changes: 1 addition & 4 deletions src/Manager/PasswordTokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
*/
class PasswordTokenManager
{
private $providerChain;

public function __construct(ProviderChainInterface $providerChain)
public function __construct(private readonly ProviderChainInterface $providerChain)
{
$this->providerChain = $providerChain;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Normalizer/JMSNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@
*/
final class JMSNormalizer implements NormalizerInterface
{
/**
* @var ArrayTransformerInterface
*/
private $normalizer;

public function __construct(ArrayTransformerInterface $normalizer)
public function __construct(private readonly ArrayTransformerInterface $normalizer)
{
$this->normalizer = $normalizer;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Normalizer/SymfonyNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@
*/
final class SymfonyNormalizer implements NormalizerInterface
{
/**
* @var SymfonyNormalizerInterface
*/
private $normalizer;

public function __construct(SymfonyNormalizerInterface $normalizer)
public function __construct(private readonly SymfonyNormalizerInterface $normalizer)
{
$this->normalizer = $normalizer;
}

/**
Expand Down
Loading

0 comments on commit 802f703

Please sign in to comment.