Skip to content

Commit

Permalink
Fix code style and psalm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jun 11, 2024
1 parent a4fd84d commit 7af768e
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 40 deletions.
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.17",
"psalm/plugin-symfony": "^3.1",
"setono/code-quality-pack": "^2.2",
"sylius/admin-api-bundle": "^1.11",
"sylius/sylius": "~1.10.14",
Expand Down Expand Up @@ -75,12 +74,8 @@
"sort-packages": true
},
"scripts": {
"analyse": [
"@ensure-test-container-exists",
"psalm"
],
"analyse": "psalm",
"check-style": "ecs check",
"ensure-test-container-exists": "[[ -f tests/Application/var/cache/test/Tests_Setono_SyliusAbandonedCartPlugin_Application_KernelTestDebugContainer.xml ]] || tests/Application/bin/console cache:warmup --env=test",
"fix-style": "ecs check --fix",
"phpunit": "phpunit"
}
Expand Down
7 changes: 0 additions & 7 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
</ignoreFiles>
</projectFiles>
<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin">
<!-- Symfony 4 container XML -->
<containerXml>tests/Application/var/cache/test/ApplicationTests_Setono_SyliusAbandonedCartPlugin_Application_KernelTestDebugContainer.xml</containerXml>

<!-- Symfony 5 container XML -->
<containerXml>tests/Application/var/cache/test/Tests_Setono_SyliusAbandonedCartPlugin_Application_KernelTestDebugContainer.xml</containerXml>
</pluginClass>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
<issueHandlers>
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Action/UnsubscribeCustomerAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(
EmailHasherInterface $emailHasher,
UnsubscribedCustomerRepositoryInterface $unsubscribedCustomerRepository,
UnsubscribedCustomerFactoryInterface $unsubscribedCustomerFactory,
Environment $twig
Environment $twig,
) {
$this->emailHasher = $emailHasher;
$this->unsubscribedCustomerRepository = $unsubscribedCustomerRepository;
Expand All @@ -50,7 +50,7 @@ public function __invoke(Request $request): Response

Assert::false(
$this->unsubscribedCustomerRepository->isUnsubscribed($email),
'setono_sylius_abandoned_cart.ui.email_already_unsubscribed'
'setono_sylius_abandoned_cart.ui.email_already_unsubscribed',
);

$this->unsubscribedCustomerRepository->add($this->unsubscribedCustomerFactory->createWithEmail($email));
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('setono_sylius_abandoned_cart');

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

/** @psalm-suppress MixedMethodCall,PossiblyNullReference,PossiblyUndefinedMethod */
Expand Down
8 changes: 4 additions & 4 deletions src/Dispatcher/NotificationDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
MessageBusInterface $commandBus,
NotificationRepositoryInterface $notificationRepository,
Registry $workflowRegistry,
int $idleThresholdInMinutes
int $idleThresholdInMinutes,
) {
$this->managerRegistry = $managerRegistry;
$this->logger = new NullLogger();
Expand All @@ -52,12 +52,12 @@ public function __construct(
public function dispatch(): void
{
$notifications = $this->notificationRepository->findNew(
new DateInterval(sprintf('PT%dM', $this->idleThresholdInMinutes))
new DateInterval(sprintf('PT%dM', $this->idleThresholdInMinutes)),
);

$this->logger->debug(sprintf(
'Notifications with associated orders that have not been updated for %d minutes will be notified',
$this->idleThresholdInMinutes
$this->idleThresholdInMinutes,
));

$dispatchCount = 0;
Expand All @@ -68,7 +68,7 @@ public function dispatch(): void
$this->logger->warning(sprintf(
'The notification with id %d could not take the transition "%s"',
(int) $notification->getId(),
NotificationWorkflow::TRANSITION_START
NotificationWorkflow::TRANSITION_START,
));

continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class CreateNotificationOnOrderPersistenceListener

public function __construct(
NotificationFactoryInterface $notificationFactory,
ManagerRegistry $managerRegistry
ManagerRegistry $managerRegistry,
) {
$this->notificationFactory = $notificationFactory;
$this->managerRegistry = $managerRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function getSubscribedEvents(): array
$event = sprintf(
'workflow.%s.transition.%s',
NotificationWorkflow::NAME,
NotificationWorkflow::TRANSITION_START
NotificationWorkflow::TRANSITION_START,
);

return [
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/OrderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class OrderFactory implements FactoryInterface

public function __construct(
FactoryInterface $decorated,
OrderTokenAssignerInterface $orderTokenAssigner
OrderTokenAssignerInterface $orderTokenAssigner,
) {
$this->decorated = $decorated;
$this->orderTokenAssigner = $orderTokenAssigner;
Expand Down
2 changes: 1 addition & 1 deletion src/Mailer/EmailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class EmailManager implements EmailManagerInterface
public function __construct(
SenderInterface $emailSender,
CartRecoveryUrlGeneratorInterface $cartRecoveryUrlGenerator,
UnsubscribeUrlGeneratorInterface $unsubscribeUrlGenerator
UnsubscribeUrlGeneratorInterface $unsubscribeUrlGenerator,
) {
$this->emailSender = $emailSender;
$this->cartRecoveryUrlGenerator = $cartRecoveryUrlGenerator;
Expand Down
4 changes: 2 additions & 2 deletions src/Message/Handler/ProcessNotificationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ProcessNotificationHandler implements MessageHandlerInterface

public function __construct(
NotificationRepositoryInterface $notificationRepository,
NotificationProcessorInterface $notificationProcessor
NotificationProcessorInterface $notificationProcessor,
) {
$this->notificationRepository = $notificationRepository;
$this->notificationProcessor = $notificationProcessor;
Expand All @@ -36,7 +36,7 @@ public function __invoke(ProcessNotification $message): void
if (null === $notification) {
throw new UnrecoverableMessageHandlingException(sprintf(
'Could not find notification with id %d',
$message->notificationId
$message->notificationId,
));
}

Expand Down
6 changes: 3 additions & 3 deletions src/Processor/NotificationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
ManagerRegistry $managerRegistry,
EmailManagerInterface $emailManager,
Registry $workflowRegistry,
NotificationEligibilityCheckerInterface $notificationEligibilityChecker
NotificationEligibilityCheckerInterface $notificationEligibilityChecker,
) {
$this->managerRegistry = $managerRegistry;
$this->emailManager = $emailManager;
Expand Down Expand Up @@ -62,7 +62,7 @@ function (NotificationInterface $notification) {
Assert::notNull($order);

$this->emailManager->sendNotification($notification);
}
},
);
} catch (Throwable $e) {
$message = sprintf(
Expand Down Expand Up @@ -99,7 +99,7 @@ private function tryTransition(NotificationInterface $notification, string $tran
$notification->addProcessingError(sprintf(
'Could not take transition "%s". The state when trying to take the transition was: "%s"',
$transition,
$notification->getState()
$notification->getState(),
));

$this->tryTransition($notification, NotificationWorkflow::TRANSITION_FAIL);
Expand Down
2 changes: 1 addition & 1 deletion src/Pruner/Pruner.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(NotificationRepositoryInterface $notificationReposit
public function prune(): void
{
$this->notificationRepository->removeOlderThan(
new DateTimeImmutable(sprintf('-%d minutes', $this->pruneOlderThan))
new DateTimeImmutable(sprintf('-%d minutes', $this->pruneOlderThan)),
);
}
}
4 changes: 2 additions & 2 deletions src/UrlGenerator/CartRecoveryUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(UrlGeneratorInterface $urlGenerator, string $route)

public function generate(
OrderInterface $order,
array $parameters = []
array $parameters = [],
): string {
$channel = $order->getChannel();
Assert::notNull($channel);
Expand All @@ -48,7 +48,7 @@ public function generate(
'%s://%s%s',
$this->urlGenerator->getContext()->getScheme(),
(string) $channel->getHostname(),
$path
$path,
);
}
}
2 changes: 1 addition & 1 deletion src/UrlGenerator/CartRecoveryUrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ interface CartRecoveryUrlGeneratorInterface
*/
public function generate(
OrderInterface $order,
array $parameters = []
array $parameters = [],
): string;
}
4 changes: 2 additions & 2 deletions src/UrlGenerator/UnsubscribeUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function generate(
ChannelInterface $channel,
string $email,
string $locale,
array $parameters = []
array $parameters = [],
): string {
$parameters = array_merge([
'email' => $email,
Expand All @@ -51,7 +51,7 @@ public function generate(
'%s://%s%s',
$this->urlGenerator->getContext()->getScheme(),
(string) $channel->getHostname(),
$path
$path,
);
}
}
2 changes: 1 addition & 1 deletion src/UrlGenerator/UnsubscribeUrlGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public function generate(
ChannelInterface $channel,
string $email,
string $locale,
array $parameters = []
array $parameters = [],
): string;
}
2 changes: 1 addition & 1 deletion tests/Factory/OrderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function it_creates_notification_when_creating_order(): void

$factory = new OrderFactory(
new Factory(Order::class),
$orderTokenAssigner->reveal()
$orderTokenAssigner->reveal(),
);
$factory->createNew();
}
Expand Down
8 changes: 4 additions & 4 deletions tests/UrlGenerator/UnsubscribeUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public function it_generates_url(): void
$urlGenerator = new UnsubscribeUrlGenerator(
$this->urlGenerator,
new EmailHasher('salt'),
'setono_sylius_abandoned_cart_shop_unsubscribe_customer'
'setono_sylius_abandoned_cart_shop_unsubscribe_customer',
);

$channel = new Channel();
$channel->setHostname('example.com');

self::assertSame(
'https://example.com/abandoned-cart/[email protected]&hash=2ac21379842b5445001475a596caab5843ecbc6be46c27f882cb6c0bd75fb9f9&utm_source=sylius&utm_medium=email&utm_campaign=Abandoned%20Cart%20Unsubscribe&_locale=en_US',
$urlGenerator->generate($channel, '[email protected]', 'en_US')
$urlGenerator->generate($channel, '[email protected]', 'en_US'),
);
}

Expand All @@ -50,7 +50,7 @@ public function it_allows_to_overwrite_parameters(): void
$urlGenerator = new UnsubscribeUrlGenerator(
$this->urlGenerator,
new EmailHasher('salt'),
'setono_sylius_abandoned_cart_shop_unsubscribe_customer'
'setono_sylius_abandoned_cart_shop_unsubscribe_customer',
);

$channel = new Channel();
Expand All @@ -61,7 +61,7 @@ public function it_allows_to_overwrite_parameters(): void
$urlGenerator->generate($channel, '[email protected]', 'en_US', [
'utm_campaign' => 'Abandoned Cart Unsubscribe #2',
'utm_content' => 'Number two',
])
]),
);
}
}

0 comments on commit 7af768e

Please sign in to comment.