Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

St 11540/feat/php 83 upgrade #39

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "eventsauce/laravel-eventsauce",
"name": "supplycart/laravel-eventsauce",
"description": "Integration support for EventSauce with the Laravel framework.",
"keywords": ["laravel", "event sourcing", "eventsauce"],
"license": "MIT",
Expand All @@ -19,18 +19,18 @@
}
],
"require": {
"php": "^7.4|^8.0",
"php": "^8.3",
"ext-json": "*",
"eventsauce/eventsauce": "^1.0|^2.0",
"illuminate/bus": "^8.0|^9.0",
"illuminate/container": "^8.0|^9.0",
"illuminate/queue": "^8.0|^9.0.0",
"illuminate/support": "^8.0|^9.0",
"eventsauce/eventsauce": "^1.0",
"illuminate/bus": "^8.0|^9.0|^10.0|^11.0",
"illuminate/container": "^8.0|^9.0|^10.0|^11.0",
"illuminate/queue": "^8.0|^9.0|^10.0|^11.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
"ramsey/uuid": "^3.8|^4.0"
},
"require-dev": {
"orchestra/testbench": "^6.0|^7.0",
"phpunit/phpunit": "^9.3"
"orchestra/testbench": "^9.0",
"phpunit/phpunit": "^10.0"
},
"suggest": {
"eventsauce/code-generation": "Generate commands and events with ease"
Expand Down
6 changes: 1 addition & 5 deletions src/AggregateRootRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

abstract class AggregateRootRepository implements EventSauceAggregateRootRepository
{
private LaravelMessageRepository $messageRepository;

protected string $aggregateRoot = '';

protected array $consumers = [];
Expand All @@ -37,14 +35,12 @@ abstract class AggregateRootRepository implements EventSauceAggregateRootReposit

protected static string $outputFile = '';

public function __construct(LaravelMessageRepository $messageRepository)
public function __construct(private LaravelMessageRepository $messageRepository)
{
if (! is_a($this->aggregateRoot, AggregateRoot::class, true)) {
throw new LogicException('You have to set an aggregate root before the repository can be initialized.');
}

$this->messageRepository = $messageRepository;

if ($this->connection) {
$this->messageRepository->setConnection($this->connection);
}
Expand Down
10 changes: 2 additions & 8 deletions src/Console/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ final class GenerateCommand extends Command

protected $description = 'Generate commands and events for aggregate roots.';

protected Filesystem $filesystem;

public function __construct(Filesystem $files)
public function __construct(protected Filesystem $filesystem)
{
parent::__construct();

$this->filesystem = $files;
}

public function handle(): void
Expand All @@ -35,9 +31,7 @@ public function handle(): void
$this->info('Start generating code...');

collect(config('eventsauce.repositories', []))
->reject(function (string $repository) {
return $repository::inputFile() === '';
})
->reject(fn(string $repository) => $repository::inputFile() === '')
->each(function (string $repository) {
$this->generateCode($repository::inputFile(), $repository::outputFile());
});
Expand Down
2 changes: 1 addition & 1 deletion src/Console/MakeAggregateRootCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function handle()
$aggregateRootIdPath,
$aggregateRootRepositoryPath,
]);
} catch (MakeFileFailed $exception) {
} catch (MakeFileFailed) {
return 1;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Console/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@

abstract class MakeCommand extends Command
{
protected Filesystem $filesystem;

public function __construct(Filesystem $files)
public function __construct(protected Filesystem $filesystem)
{
parent::__construct();

$this->filesystem = $files;
}

protected function formatClassName(string $namespace): string
Expand Down
2 changes: 1 addition & 1 deletion src/Console/MakeConsumerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function handle()
$this->ensureValidPaths([
$consumerPath,
]);
} catch (MakeFileFailed $exception) {
} catch (MakeFileFailed) {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class Consumer implements EventSauceConsumer
public function handle(Message $message): void
{
$event = $message->event();
$parts = explode('\\', get_class($event));
$parts = explode('\\', $event::class);
$method = 'handle'.end($parts);

if (method_exists($this, $method)) {
Expand Down
8 changes: 2 additions & 6 deletions src/EventSauceServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ public function register()
MakeConsumerCommand::class,
]);

$this->app->bind(MessageSerializer::class, function ($app) {
return $app->make(ConstructingMessageSerializer::class);
});
$this->app->bind(MessageSerializer::class, fn($app) => $app->make(ConstructingMessageSerializer::class));

$this->app->bind(MessageDecorator::class, function ($app) {
return $app->make(DefaultHeadersDecorator::class);
});
$this->app->bind(MessageDecorator::class, fn($app) => $app->make(DefaultHeadersDecorator::class));
}

public function provides()
Expand Down
5 changes: 1 addition & 4 deletions src/HandleConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ final class HandleConsumer implements ShouldQueue
use InteractsWithQueue;
use Queueable;

private string $consumer;

/** @var Message[] */
private $messages = [];

public function __construct(string $consumer, Message ...$messages)
public function __construct(private string $consumer, Message ...$messages)
{
$this->consumer = $consumer;
$this->messages = $messages;
}

Expand Down
2 changes: 1 addition & 1 deletion src/LaravelMessageDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function dispatch(Message ...$messages): void
$dispatch->onQueue($this->queue);
}
} else {
dispatch_now(new HandleConsumer($consumer, ...$messages));
dispatch_sync(new HandleConsumer($consumer, ...$messages));
}
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/LaravelMessageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,12 @@

final class LaravelMessageRepository implements MessageRepository
{
private DatabaseManager $database;

private MessageSerializer $serializer;

private string $connection;

private string $table;

public function __construct(DatabaseManager $database, MessageSerializer $serializer, Config $config)
public function __construct(private DatabaseManager $database, private MessageSerializer $serializer, Config $config)
{
$this->database = $database;
$this->serializer = $serializer;
$this->connection = (string) $config->get('eventsauce.connection');
$this->table = (string) $config->get('eventsauce.table');
}
Expand All @@ -38,9 +32,7 @@ public function persist(Message ...$messages): void
{
$connection = $this->connection();

collect($messages)->map(function (Message $message) {
return $this->serializer->serializeMessage($message);
})->each(function (array $message) use ($connection) {
collect($messages)->map(fn(Message $message) => $this->serializer->serializeMessage($message))->each(function (array $message) use ($connection) {
$headers = $message['headers'];

$connection->table($this->table)->insert([
Expand Down
3 changes: 1 addition & 2 deletions tests/Fixtures/NewUserNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ final class NewUserNotification extends Notification
/**
* Get the notification's channels.
*
* @param mixed $notifiable
* @return array|string
*/
public function via($notifiable)
public function via(mixed $notifiable)
{
return ['mail'];
}
Expand Down
8 changes: 1 addition & 7 deletions tests/Fixtures/RegisterUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@

final class RegisterUser
{
private string $name;

private string $email;

public function __construct(string $name, string $email)
public function __construct(private string $name, private string $email)
{
$this->name = $name;
$this->email = $email;
}

public function name(): string
Expand Down
5 changes: 1 addition & 4 deletions tests/Fixtures/RegistrationAggregateRootId.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

final class RegistrationAggregateRootId implements AggregateRootId
{
private string $identifier;

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

public function toString(): string
Expand Down
8 changes: 1 addition & 7 deletions tests/Fixtures/UserWasRegistered.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@

final class UserWasRegistered implements SerializablePayload
{
private string $name;

private string $email;

public function __construct(string $name, string $email)
public function __construct(private string $name, private string $email)
{
$this->name = $name;
$this->email = $email;
}

public function name(): string
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getPackageProviders($app)
protected function getUserWasRegisteredMessage(RegistrationAggregateRootId $id = null): Message
{
$event = new UserWasRegistered('Dries Vints', '[email protected]');
$id = $id ?? RegistrationAggregateRootId::create();
$id ??= RegistrationAggregateRootId::create();

return (new DefaultHeadersDecorator())
->decorate(new Message($event, [Header::AGGREGATE_ROOT_ID => $id]));
Expand Down