Skip to content

Commit

Permalink
improve output style
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Feb 7, 2024
1 parent 508eedd commit 8c2ecfb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
37 changes: 21 additions & 16 deletions src/Console/OutputStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,37 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Throwable;

use function array_keys;
use function array_values;
use function sprintf;

final class OutputStyle extends SymfonyStyle
{
public function message(EventSerializer $serializer, Message $message): void
{
$event = $message->event();
$data = $serializer->serialize($event, [Encoder::OPTION_PRETTY_PRINT => true]);

try {
$data = $serializer->serialize($event, [Encoder::OPTION_PRETTY_PRINT => true]);
} catch (Throwable $error) {
$this->error(sprintf('Error while serializing event: %s', $error->getMessage()));

if ($this->isVeryVerbose()) {
$this->throwable($error);
}

return;
}

$this->title($data->name);

$this->horizontalTable([
'eventClass',
'aggregateName',
'aggregateId',
'playhead',
'recordedOn',
], [
[
$event::class,
$message->aggregateName(),
$message->aggregateId(),
$message->playhead(),
$message->recordedOn()->format(DateTimeInterface::ATOM),
],
]);
$headers = $message->headers();

if ($headers['recordedOn'] ?? null) {
$headers['recordedOn'] = $headers['recordedOn']->format(DateTimeInterface::ATOM);

Check failure on line 41 in src/Console/OutputStyle.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

PossiblyUndefinedArrayOffset

src/Console/OutputStyle.php:41:38: PossiblyUndefinedArrayOffset: Possibly undefined array key $headers['recordedOn'] on array{aggregateId?: string, aggregateName?: string, archived?: bool, newStreamStart?: bool, playhead?: int<1, max>, recordedOn?: DateTimeImmutable} (see https://psalm.dev/167)

Check failure on line 41 in src/Console/OutputStyle.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

PossiblyNullReference

src/Console/OutputStyle.php:41:62: PossiblyNullReference: Cannot call method format on possibly null value (see https://psalm.dev/083)
}

$this->horizontalTable(array_keys($headers), [array_values($headers)]);

$this->block($data->payload);
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Console/OutputStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public function testWrite(): void
$content = $output->fetch();

self::assertStringContainsString('profile.created', $content);
self::assertStringContainsString('Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated', $content);
self::assertStringContainsString('Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile', $content);
self::assertStringContainsString('profile', $content);
self::assertStringContainsString('{"id":"1","email":"[email protected]"}', $content);
}
}

0 comments on commit 8c2ecfb

Please sign in to comment.