for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Shippinno\Notification\Infrastructure\Domain\Model;
use Shippinno\Notification\Domain\Model\DeduplicationKey;
use Shippinno\Notification\Domain\Model\Notification;
use Shippinno\Notification\Domain\Model\NotificationId;
use Shippinno\Notification\Domain\Model\NotificationRepository;
class InMemoryNotificationRepository implements NotificationRepository
{
/**
* @var Notification[]
*/
private $notifications = [];
private $nextIdentity = 1;
* {@inheritdoc}
public function add(Notification $notification): void
$deduplicationKey = $notification->deduplicationKey();
if (!is_null($deduplicationKey) && $this->hasNotificationOfDeduplicationKey($deduplicationKey)) {
return;
}
$this->notifications[$this->nextIdentity()->id()] = $notification;
public function notificationOfId(NotificationId $notificationId): ?Notification
if (!isset($this->notifications[$notificationId->id()])) {
return null;
return $this->notifications[$notificationId->id()];
public function hasNotificationOfDeduplicationKey(DeduplicationKey $deduplicationKey): bool
foreach ($this->notifications as $notification) {
if ($notification->deduplicationKey()->equals($deduplicationKey)) {
return true;
public function unsentNotifications(): array
return array_filter($this->notifications, function (Notification $notification) {
return !$notification->isSent();
});
* @return NotificationId
private function nextIdentity(): NotificationId
return new NotificationId($this->nextIdentity++);