Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
},
"require-dev": {
"phpunit/phpunit": "^9",
"ibexa/code-style": "^1.1",
"ibexa/code-style": "~2.3.1",
"ibexa/doctrine-schema": "~4.6.x-dev",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"qossmic/deptrac-shim": "^0.24.0 || ^1.0.2"
"qossmic/deptrac-shim": "^0.24.0 || ^1.0.2",
"ibexa/doctrine-migrations": "~4.6.x-dev"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ public function addSemanticConfig(NodeBuilder $nodeBuilder): void
/**
* @param array<string, array<string, mixed>> $scopeSettings
*/
public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerInterface $contextualizer): void
{
public function mapConfig(
array &$scopeSettings,
$currentScope,
ContextualizerInterface $contextualizer
): void {
if (empty($scopeSettings['notifier'])) {
return;
}
Expand All @@ -70,8 +73,10 @@ public function mapConfig(array &$scopeSettings, $currentScope, ContextualizerIn
/**
* @param array<string, mixed> $config
*/
public function postMap(array $config, ContextualizerInterface $contextualizer): void
{
public function postMap(
array $config,
ContextualizerInterface $contextualizer
): void {
foreach (self::MAPPED_SETTINGS as $setting) {
$contextualizer->mapConfigArray(sprintf('notifications.%s', $setting), $config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ final class IbexaNotificationsExtension extends Extension implements PrependExte
/**
* @param array<string, mixed> $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
public function load(
array $configs,
ContainerBuilder $container
): void {
$loader = new YamlFileLoader(
$container,
new FileLocator(__DIR__ . '/../Resources/config')
Expand Down
3 changes: 2 additions & 1 deletion src/bundle/IbexaNotificationsBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Ibexa\Bundle\Notifications;

use Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension;
use Ibexa\Bundle\Notifications\DependencyInjection\Configuration\Parser\NotificationsConfigParser;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -16,7 +17,7 @@ final class IbexaNotificationsBundle extends Bundle
{
public function build(ContainerBuilder $container): void
{
/** @var \Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension $core */
/** @var IbexaCoreExtension $core */
$core = $container->getExtension('ibexa');

$core->addConfigParser(new NotificationsConfigParser());
Expand Down
8 changes: 6 additions & 2 deletions src/contracts/Service/NotificationServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
namespace Ibexa\Contracts\Notifications\Service;

use Ibexa\Contracts\Notifications\Value\NotificationInterface;
use Ibexa\Contracts\Notifications\Value\RecipientInterface;

interface NotificationServiceInterface
{
/**
* @param array<\Ibexa\Contracts\Notifications\Value\RecipientInterface> $recipients
* @param array<RecipientInterface> $recipients
*/
public function send(NotificationInterface $notification, array $recipients = []): void;
public function send(
NotificationInterface $notification,
array $recipients = []
): void;
}
6 changes: 4 additions & 2 deletions src/contracts/SystemNotification/SystemMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ final class SystemMessage implements MessageInterface
/**
* @param array<string, mixed> $context
*/
public function __construct(UserReference $user, array $context = [])
{
public function __construct(
UserReference $user,
array $context = []
) {
$this->user = $user;
$this->context = $context;
}
Expand Down
6 changes: 4 additions & 2 deletions src/contracts/SystemNotification/SystemNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public function setContent(string $content): void
$this->content($content);
}

public function asSystemNotification(UserRecipientInterface $recipient, ?string $transport = null): SystemMessage
{
public function asSystemNotification(
UserRecipientInterface $recipient,
?string $transport = null
): SystemMessage {
$context = [
'subject' => $this->getSubject(),
'content' => $this->getContent(),
Expand Down
3 changes: 2 additions & 1 deletion src/lib/Mapper/NotificationMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Ibexa\Notifications\Mapper;

use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
use Ibexa\Contracts\Notifications\Value\NotificationInterface;
use Symfony\Component\Notifier\Notification\Notification;

Expand All @@ -16,7 +17,7 @@ interface NotificationMapperInterface
/**
* Produces Symfony Notifier's compatible Notification object.
*
* @throws \Ibexa\Contracts\Core\Exception\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function mapToSymfonyNotification(NotificationInterface $notification): Notification;
}
3 changes: 2 additions & 1 deletion src/lib/Mapper/RecipientMapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Ibexa\Notifications\Mapper;

use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
use Ibexa\Contracts\Notifications\Value\RecipientInterface;
use Symfony\Component\Notifier\Recipient\RecipientInterface as SymfonyRecipientInterface;

Expand All @@ -16,7 +17,7 @@ interface RecipientMapperInterface
/**
* Produces Symfony Notifier's compatible RecipientInterface object.
*
* @throws \Ibexa\Contracts\Core\Exception\InvalidArgumentException
* @throws InvalidArgumentException
*/
public function mapToSymfonyRecipient(RecipientInterface $recipient): SymfonyRecipientInterface;
}
9 changes: 6 additions & 3 deletions src/lib/Service/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Ibexa\Contracts\Notifications\Service\NotificationServiceInterface;
use Ibexa\Contracts\Notifications\Value\NotificationInterface;
use Ibexa\Contracts\Notifications\Value\RecipientInterface;
use Ibexa\Notifications\Mapper\NotificationMapperInterface;
use Ibexa\Notifications\Mapper\RecipientMapperInterface;
use Ibexa\Notifications\SubscriptionResolver\SubscriptionResolverInterface;
Expand Down Expand Up @@ -39,10 +40,12 @@ public function __construct(
}

/**
* @param array<\Ibexa\Contracts\Notifications\Value\RecipientInterface> $recipients
* @param array<RecipientInterface> $recipients
*/
public function send(NotificationInterface $notification, array $recipients = []): void
{
public function send(
NotificationInterface $notification,
array $recipients = []
): void {
$channels = array_map(
static fn (
ChannelSubscription $channelSubscription
Expand Down
10 changes: 6 additions & 4 deletions src/lib/SubscriptionResolver/ChainSubscriptionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@

final class ChainSubscriptionResolver implements SubscriptionResolverInterface
{
/** @var iterable<\Ibexa\Notifications\SubscriptionResolver\SubscriptionResolverInterface> */
/** @var iterable<SubscriptionResolverInterface> */
private iterable $resolvers;

/**
* @param iterable<\Ibexa\Notifications\SubscriptionResolver\SubscriptionResolverInterface> $resolvers
* @param iterable<SubscriptionResolverInterface> $resolvers
*/
public function __construct(iterable $resolvers)
{
$this->resolvers = $resolvers;
}

public function resolve(NotificationInterface $notification, array $context = []): iterable
{
public function resolve(
NotificationInterface $notification,
array $context = []
): iterable {
foreach ($this->resolvers as $resolver) {
$channelSubscriptions = $resolver->resolve($notification, $context);
foreach ($channelSubscriptions as $channelSubscription) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public function __construct(ConfigResolverInterface $configResolver)
$this->configResolver = $configResolver;
}

public function resolve(NotificationInterface $notification, array $context = []): iterable
{
public function resolve(
NotificationInterface $notification,
array $context = []
): iterable {
$config = $this->configResolver->getParameter('notifications.subscriptions');
$notificationType = $notification->getType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
namespace Ibexa\Notifications\SubscriptionResolver;

use Ibexa\Contracts\Notifications\Value\NotificationInterface;
use Ibexa\Notifications\Value\ChannelSubscription;

interface SubscriptionResolverInterface
{
/**
* @param array<string, mixed> $context
*
* @return \Iterator<\Ibexa\Notifications\Value\ChannelSubscription|null>
* @return \Iterator<ChannelSubscription|null>
*/
public function resolve(NotificationInterface $notification, array $context = []): iterable;
public function resolve(
NotificationInterface $notification,
array $context = []
): iterable;
}
23 changes: 15 additions & 8 deletions src/lib/SystemNotification/SystemNotificationChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ final class SystemNotificationChannel implements ChannelInterface

private NotificationService $notificationService;

public function __construct(Repository $repository, NotificationService $notificationService)
{
public function __construct(
Repository $repository,
NotificationService $notificationService
) {
$this->repository = $repository;
$this->notificationService = $notificationService;
}

/**
* @param \Symfony\Component\Notifier\Notification\Notification&\Ibexa\Contracts\Notifications\SystemNotification\SystemNotificationInterface $notification
* @param \Ibexa\Contracts\Notifications\Value\Recipent\UserRecipientInterface $recipient
* @param Notification&SystemNotificationInterface $notification
* @param UserRecipientInterface $recipient
*/
public function notify(Notification $notification, RecipientInterface $recipient, ?string $transportName = null): void
{
public function notify(
Notification $notification,
RecipientInterface $recipient,
?string $transportName = null
): void {
$message = $notification->asSystemNotification($recipient, $transportName);
if ($message === null) {
return;
Expand All @@ -56,8 +61,10 @@ public function notify(Notification $notification, RecipientInterface $recipient
}
}

public function supports(Notification $notification, RecipientInterface $recipient): bool
{
public function supports(
Notification $notification,
RecipientInterface $recipient
): bool {
return $notification instanceof SystemNotificationInterface && $recipient instanceof UserRecipientInterface;
}
}
6 changes: 4 additions & 2 deletions src/lib/Value/ChannelSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ final class ChannelSubscription

private string $channel;

public function __construct(string $notificationType, string $channel)
{
public function __construct(
string $notificationType,
string $channel
) {
$this->notificationType = $notificationType;
$this->channel = $channel;
}
Expand Down
16 changes: 10 additions & 6 deletions tests/lib/Channel/SystemNotificationChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Ibexa\Contracts\Notifications\SystemNotification\SystemNotificationInterface;
use Ibexa\Contracts\Notifications\Value\Recipent\UserRecipientInterface;
use Ibexa\Notifications\SystemNotification\SystemNotificationChannel;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Recipient\RecipientInterface;
Expand All @@ -25,10 +26,10 @@ final class SystemNotificationChannelTest extends TestCase
{
private const EXAMPLE_USER_ID = 12;

/** @var \Ibexa\Contracts\Core\Repository\Repository&\PHPUnit\Framework\MockObject\MockObject */
/** @var Repository&MockObject */
private Repository $repository;

/** @var \Ibexa\Contracts\Core\Repository\NotificationService&\PHPUnit\Framework\MockObject\MockObject */
/** @var NotificationService&MockObject */
private NotificationService $notificationService;

private SystemNotificationChannel $channel;
Expand All @@ -44,13 +45,16 @@ protected function setUp(): void
/**
* @dataProvider dataProviderForTestSupports
*/
public function testSupports(Notification $notification, RecipientInterface $recipient, bool $expectedResult): void
{
public function testSupports(
Notification $notification,
RecipientInterface $recipient,
bool $expectedResult
): void {
self::assertEquals($expectedResult, $this->channel->supports($notification, $recipient));
}

/**
* @return iterable<string, array{\Symfony\Component\Notifier\Notification\Notification, \Symfony\Component\Notifier\Recipient\RecipientInterface, bool}>
* @return iterable<string, array{Notification, RecipientInterface, bool}>
*/
public function dataProviderForTestSupports(): iterable
{
Expand Down Expand Up @@ -99,7 +103,7 @@ public function testNotify(): void
}

/**
* @return \Symfony\Component\Notifier\Notification\Notification&\Ibexa\Contracts\Notifications\SystemNotification\SystemNotificationInterface
* @return Notification&SystemNotificationInterface
*/
private function createSupportedNotification(?SystemMessage $message = null): Notification
{
Expand Down
13 changes: 8 additions & 5 deletions tests/lib/SubscriptionResolver/ChainSubscriptionResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@
use Ibexa\Contracts\Notifications\Value\NotificationInterface;
use Ibexa\Notifications\SubscriptionResolver\ChainSubscriptionResolver;
use Ibexa\Notifications\SubscriptionResolver\SubscriptionResolverInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

final class ChainSubscriptionResolverTest extends TestCase
{
/**
* @dataProvider provideForTestResolve
*
* @param array<\Ibexa\Notifications\SubscriptionResolver\SubscriptionResolverInterface> $resolvers
* @param array<SubscriptionResolverInterface> $resolvers
* @param array<string|null> $expectedChannels
*/
public function testResolve(array $resolvers, array $expectedChannels): void
{
public function testResolve(
array $resolvers,
array $expectedChannels
): void {
$subscriptionResolver = new ChainSubscriptionResolver($resolvers);

$notification = $this->createMock(NotificationInterface::class);
Expand All @@ -33,7 +36,7 @@ public function testResolve(array $resolvers, array $expectedChannels): void

/**
* @return iterable<string, array{
* array<\Ibexa\Notifications\SubscriptionResolver\SubscriptionResolverInterface|null>,
* array<SubscriptionResolverInterface|null>,
* array<string>,
* }>
*/
Expand All @@ -59,7 +62,7 @@ public function provideForTestResolve(): iterable
/**
* @param array<string|null> $channels
*
* @return \Ibexa\Notifications\SubscriptionResolver\SubscriptionResolverInterface&\PHPUnit\Framework\MockObject\MockObject
* @return SubscriptionResolverInterface&MockObject
*/
private function mockResolver(array $channels): SubscriptionResolverInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Ibexa\Contracts\Notifications\Value\NotificationInterface;
use Ibexa\Notifications\SubscriptionResolver\ConfigBasedSubscriptionResolver;
use Ibexa\Notifications\Value\ChannelSubscription;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -21,7 +22,7 @@ final class ConfigBasedSubscriptionResolverTest extends TestCase
{
private ConfigBasedSubscriptionResolver $resolver;

/** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface|\PHPUnit\Framework\MockObject\MockObject */
/** @var ConfigResolverInterface|MockObject */
private ConfigResolverInterface $configResolver;

public function setUp(): void
Expand Down
Loading