Skip to content

Commit

Permalink
Merge pull request #32 from Setono/rector
Browse files Browse the repository at this point in the history
Use PHP 8.1 syntax
  • Loading branch information
loevgaard authored Oct 8, 2024
2 parents dc5df4a + 9ca1734 commit 55448c4
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 135 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"sylius/channel": "^1.0",
"sylius/core": "^1.0",
"sylius/core-bundle": "^1.0",
"sylius/mailer-bundle": "^1.0",
"sylius/mailer-bundle": "^1.0 || ^2.0",
"sylius/order": "^1.0",
"sylius/resource-bundle": "^1.6",
"sylius/ui-bundle": "^1.0",
Expand Down
25 changes: 25 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->cacheClass(FileCacheStorage::class);
$rectorConfig->cacheDirectory('./.build/rector');

$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

$rectorConfig->skip([
__DIR__ . '/tests/Application',
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81
]);
};
6 changes: 1 addition & 5 deletions src/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@ final class ProcessCommand extends Command
/** @var string|null */
protected static $defaultDescription = 'Process pending notifications';

private NotificationDispatcherInterface $notificationDispatcher;

public function __construct(NotificationDispatcherInterface $notificationDispatcher)
public function __construct(private readonly NotificationDispatcherInterface $notificationDispatcher)
{
parent::__construct();

$this->notificationDispatcher = $notificationDispatcher;
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
6 changes: 1 addition & 5 deletions src/Command/PruneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ final class PruneCommand extends Command
/** @var string|null */
protected static $defaultDescription = 'Prune older notifications';

private PrunerInterface $pruner;

public function __construct(PrunerInterface $pruner)
public function __construct(private readonly PrunerInterface $pruner)
{
parent::__construct();

$this->pruner = $pruner;
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down
20 changes: 4 additions & 16 deletions src/Controller/Action/UnsubscribeCustomerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,12 @@

final class UnsubscribeCustomerAction
{
private EmailHasherInterface $emailHasher;

private UnsubscribedCustomerRepositoryInterface $unsubscribedCustomerRepository;

private UnsubscribedCustomerFactoryInterface $unsubscribedCustomerFactory;

private Environment $twig;

public function __construct(
EmailHasherInterface $emailHasher,
UnsubscribedCustomerRepositoryInterface $unsubscribedCustomerRepository,
UnsubscribedCustomerFactoryInterface $unsubscribedCustomerFactory,
Environment $twig,
private readonly EmailHasherInterface $emailHasher,
private readonly UnsubscribedCustomerRepositoryInterface $unsubscribedCustomerRepository,
private readonly UnsubscribedCustomerFactoryInterface $unsubscribedCustomerFactory,
private readonly Environment $twig,
) {
$this->emailHasher = $emailHasher;
$this->unsubscribedCustomerRepository = $unsubscribedCustomerRepository;
$this->unsubscribedCustomerFactory = $unsubscribedCustomerFactory;
$this->twig = $twig;
}

public function __invoke(Request $request): Response
Expand Down
20 changes: 4 additions & 16 deletions src/Dispatcher/NotificationDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,15 @@ final class NotificationDispatcher implements NotificationDispatcherInterface, L

private ?WorkflowInterface $workflow = null;

private MessageBusInterface $commandBus;

private NotificationRepositoryInterface $notificationRepository;

private Registry $workflowRegistry;

private int $idleThresholdInMinutes;

public function __construct(
ManagerRegistry $managerRegistry,
MessageBusInterface $commandBus,
NotificationRepositoryInterface $notificationRepository,
Registry $workflowRegistry,
int $idleThresholdInMinutes,
private readonly MessageBusInterface $commandBus,
private readonly NotificationRepositoryInterface $notificationRepository,
private readonly Registry $workflowRegistry,
private readonly int $idleThresholdInMinutes,
) {
$this->managerRegistry = $managerRegistry;
$this->logger = new NullLogger();
$this->commandBus = $commandBus;
$this->notificationRepository = $notificationRepository;
$this->workflowRegistry = $workflowRegistry;
$this->idleThresholdInMinutes = $idleThresholdInMinutes;
}

public function dispatch(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@

final class UnsubscribedCustomerNotificationEligibilityChecker implements NotificationEligibilityCheckerInterface
{
private UnsubscribedCustomerRepositoryInterface $unsubscribedCustomerRepository;

public function __construct(UnsubscribedCustomerRepositoryInterface $unsubscribedCustomerRepository)
public function __construct(private readonly UnsubscribedCustomerRepositoryInterface $unsubscribedCustomerRepository)
{
$this->unsubscribedCustomerRepository = $unsubscribedCustomerRepository;
}

public function check(NotificationInterface $notification): EligibilityCheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ final class CreateNotificationOnOrderPersistenceListener
{
use ORMTrait;

private NotificationFactoryInterface $notificationFactory;

public function __construct(
NotificationFactoryInterface $notificationFactory,
private readonly NotificationFactoryInterface $notificationFactory,
ManagerRegistry $managerRegistry,
) {
$this->notificationFactory = $notificationFactory;
$this->managerRegistry = $managerRegistry;
}

Expand Down
5 changes: 1 addition & 4 deletions src/Factory/NotificationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

final class NotificationFactory implements NotificationFactoryInterface
{
private FactoryInterface $decorated;

public function __construct(FactoryInterface $decorated)
public function __construct(private readonly FactoryInterface $decorated)
{
$this->decorated = $decorated;
}

public function createNew(): NotificationInterface
Expand Down
10 changes: 2 additions & 8 deletions src/Factory/OrderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@
*/
final class OrderFactory implements FactoryInterface
{
private FactoryInterface $decorated;

private OrderTokenAssignerInterface $orderTokenAssigner;

public function __construct(
FactoryInterface $decorated,
OrderTokenAssignerInterface $orderTokenAssigner,
private readonly FactoryInterface $decorated,
private readonly OrderTokenAssignerInterface $orderTokenAssigner,
) {
$this->decorated = $decorated;
$this->orderTokenAssigner = $orderTokenAssigner;
}

public function createNew(): object
Expand Down
5 changes: 1 addition & 4 deletions src/Factory/UnsubscribedCustomerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

final class UnsubscribedCustomerFactory implements UnsubscribedCustomerFactoryInterface
{
private FactoryInterface $decorated;

public function __construct(FactoryInterface $decorated)
public function __construct(private readonly FactoryInterface $decorated)
{
$this->decorated = $decorated;
}

public function createNew(): UnsubscribedCustomerInterface
Expand Down
5 changes: 1 addition & 4 deletions src/Hasher/EmailHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

final class EmailHasher implements EmailHasherInterface
{
private string $salt;

public function __construct(string $salt)
public function __construct(private readonly string $salt)
{
$this->salt = $salt;
}

public function hash(string $email): string
Expand Down
15 changes: 3 additions & 12 deletions src/Mailer/EmailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,11 @@

final class EmailManager implements EmailManagerInterface
{
private SenderInterface $emailSender;

private CartRecoveryUrlGeneratorInterface $cartRecoveryUrlGenerator;

private UnsubscribeUrlGeneratorInterface $unsubscribeUrlGenerator;

public function __construct(
SenderInterface $emailSender,
CartRecoveryUrlGeneratorInterface $cartRecoveryUrlGenerator,
UnsubscribeUrlGeneratorInterface $unsubscribeUrlGenerator,
private readonly SenderInterface $emailSender,
private readonly CartRecoveryUrlGeneratorInterface $cartRecoveryUrlGenerator,
private readonly UnsubscribeUrlGeneratorInterface $unsubscribeUrlGenerator,
) {
$this->emailSender = $emailSender;
$this->cartRecoveryUrlGenerator = $cartRecoveryUrlGenerator;
$this->unsubscribeUrlGenerator = $unsubscribeUrlGenerator;
}

public function sendNotification(NotificationInterface $notification): void
Expand Down
10 changes: 2 additions & 8 deletions src/Message/Handler/ProcessNotificationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@

final class ProcessNotificationHandler implements MessageHandlerInterface
{
private NotificationRepositoryInterface $notificationRepository;

private NotificationProcessorInterface $notificationProcessor;

public function __construct(
NotificationRepositoryInterface $notificationRepository,
NotificationProcessorInterface $notificationProcessor,
private readonly NotificationRepositoryInterface $notificationRepository,
private readonly NotificationProcessorInterface $notificationProcessor,
) {
$this->notificationRepository = $notificationRepository;
$this->notificationProcessor = $notificationProcessor;
}

public function __invoke(ProcessNotification $message): void
Expand Down
15 changes: 3 additions & 12 deletions src/Processor/NotificationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,13 @@ final class NotificationProcessor implements NotificationProcessorInterface

private ?WorkflowInterface $workflow = null;

private EmailManagerInterface $emailManager;

private Registry $workflowRegistry;

private NotificationEligibilityCheckerInterface $notificationEligibilityChecker;

public function __construct(
ManagerRegistry $managerRegistry,
EmailManagerInterface $emailManager,
Registry $workflowRegistry,
NotificationEligibilityCheckerInterface $notificationEligibilityChecker,
private readonly EmailManagerInterface $emailManager,
private readonly Registry $workflowRegistry,
private readonly NotificationEligibilityCheckerInterface $notificationEligibilityChecker,
) {
$this->managerRegistry = $managerRegistry;
$this->emailManager = $emailManager;
$this->workflowRegistry = $workflowRegistry;
$this->notificationEligibilityChecker = $notificationEligibilityChecker;
}

public function process(NotificationInterface $notification): void
Expand Down
12 changes: 4 additions & 8 deletions src/Pruner/Pruner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@

final class Pruner implements PrunerInterface
{
private NotificationRepositoryInterface $notificationRepository;

private int $pruneOlderThan;

public function __construct(NotificationRepositoryInterface $notificationRepository, int $pruneOlderThan)
{
$this->notificationRepository = $notificationRepository;
$this->pruneOlderThan = $pruneOlderThan;
public function __construct(
private readonly NotificationRepositoryInterface $notificationRepository,
private readonly int $pruneOlderThan,
) {
}

public function prune(): void
Expand Down
14 changes: 5 additions & 9 deletions src/UrlGenerator/CartRecoveryUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@

final class CartRecoveryUrlGenerator implements CartRecoveryUrlGeneratorInterface
{
private UrlGeneratorInterface $urlGenerator;

private string $route;

public function __construct(UrlGeneratorInterface $urlGenerator, string $route)
{
$this->urlGenerator = $urlGenerator;
$this->route = $route;
public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
private readonly string $route,
) {
}

public function generate(
Expand All @@ -38,7 +34,7 @@ public function generate(

try {
$path = $this->urlGenerator->generate($this->route, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
} catch (SessionNotFoundException $e) {
} catch (SessionNotFoundException) {
// it's a long story, but this exception is thrown if the store doesn't use locale based channels
unset($parameters['_locale']);
$path = $this->urlGenerator->generate($this->route, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
Expand Down
18 changes: 6 additions & 12 deletions src/UrlGenerator/UnsubscribeUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@

final class UnsubscribeUrlGenerator implements UnsubscribeUrlGeneratorInterface
{
private UrlGeneratorInterface $urlGenerator;

private EmailHasherInterface $emailHasher;

private string $route;

public function __construct(UrlGeneratorInterface $urlGenerator, EmailHasherInterface $emailHasher, string $route)
{
$this->urlGenerator = $urlGenerator;
$this->emailHasher = $emailHasher;
$this->route = $route;
public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
private readonly EmailHasherInterface $emailHasher,
private readonly string $route,
) {
}

public function generate(
Expand All @@ -41,7 +35,7 @@ public function generate(

try {
$path = $this->urlGenerator->generate($this->route, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
} catch (SessionNotFoundException $e) {
} catch (SessionNotFoundException) {
// it's a long story, but this exception is thrown if the store doesn't use locale based channels
unset($parameters['_locale']);
$path = $this->urlGenerator->generate($this->route, $parameters, UrlGeneratorInterface::ABSOLUTE_PATH);
Expand Down
5 changes: 2 additions & 3 deletions tests/Pruner/PrunerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ public function it_prunes(): void
$expected = (new \DateTimeImmutable())->sub(new \DateInterval('PT30M'));

$repository = $this->prophesize(NotificationRepositoryInterface::class);
$repository->removeOlderThan(Argument::that(static function (\DateTimeInterface $dateTime) use ($expected) {
$repository->removeOlderThan(Argument::that(static fn (\DateTimeInterface $dateTime) =>
// the reason we don't do an exact match between the two timestamps is that this test allows a second to pass
// between call of the method and the instantiation of the new DateTime object
return abs($dateTime->getTimestamp() - $expected->getTimestamp()) <= 1;
}))->shouldBeCalled();
abs($dateTime->getTimestamp() - $expected->getTimestamp()) <= 1))->shouldBeCalled();

$pruner = new Pruner($repository->reveal(), 30);
$pruner->prune();
Expand Down

0 comments on commit 55448c4

Please sign in to comment.