Skip to content
Merged
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
17 changes: 17 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@
"clean_namespace": true,
"declare_strict_types": true,
"list_syntax": true,
"no_empty_phpdoc": true,
"no_superfluous_elseif": true,
"no_superfluous_phpdoc_tags": {
"remove_inheritdoc": true
},
"no_unneeded_braces": true,
"no_useless_nullsafe_operator": true,
"no_whitespace_before_comma_in_array": true,
"normalize_index_brace": true,
"nullable_type_declaration": true,
"nullable_type_declaration_for_default_null_value": true,
"ordered_attributes": true,
"ordered_traits": true,
"ordered_types": {
"null_adjustment": "always_last"
},
"phpdoc_summary": true,
"phpdoc_trim": true,
"phpdoc_types": true,
"phpdoc_types_order": {
"null_adjustment": "always_last"
},
"simple_to_complex_string_variable": true,
"ternary_to_null_coalescing": true,
"trailing_comma_in_multiline": {
Expand Down
15 changes: 2 additions & 13 deletions src/Application/Bus/CommandDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@
class CommandDispatcher implements ICommandDispatcher
{
/**
* @var array<string|callable>
* @var array<callable|string>
*/
private array $pipes = [];

/**
* CommandDispatcher constructor.
*
* @param CommandHandlerContainer $handlers
* @param PipeContainer|null $middleware
*/
public function __construct(
private readonly CommandHandlerContainer $handlers,
private readonly ?PipeContainer $middleware = null,
Expand All @@ -42,8 +36,7 @@ public function __construct(
/**
* Dispatch messages through the provided pipes.
*
* @param array<string|callable> $pipes
* @return void
* @param array<callable|string> $pipes
*/
public function through(array $pipes): void
{
Expand All @@ -52,9 +45,6 @@ public function through(array $pipes): void
$this->pipes = $pipes;
}

/**
* @inheritDoc
*/
public function dispatch(Command $command): Result
{
$pipeline = PipelineBuilder::make($this->middleware)
Expand All @@ -71,7 +61,6 @@ public function dispatch(Command $command): Result
}

/**
* @param Command $command
* @return Result<mixed>
*/
private function execute(Command $command): Result
Expand Down
11 changes: 0 additions & 11 deletions src/Application/Bus/CommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@

final readonly class CommandHandler implements ICommandHandler
{
/**
* CommandHandler constructor.
*
* @param object $handler
*/
public function __construct(private object $handler)
{
}

/**
* @inheritDoc
*/
public function __invoke(Command $command): Result
{
assert(method_exists($this->handler, 'execute'), sprintf(
Expand All @@ -46,9 +38,6 @@ public function __invoke(Command $command): Result
return $result;
}

/**
* @inheritDoc
*/
public function middleware(): array
{
if ($this->handler instanceof DispatchThroughMiddleware) {
Expand Down
15 changes: 6 additions & 9 deletions src/Application/Bus/CommandHandlerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,28 @@
namespace CloudCreativity\Modules\Application\Bus;

use Closure;
use CloudCreativity\Modules\Application\ApplicationException;
use CloudCreativity\Modules\Contracts\Application\Bus\CommandHandlerContainer as ICommandHandlerContainer;
use RuntimeException;
use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command;

final class CommandHandlerContainer implements ICommandHandlerContainer
{
/**
* @var array<string, Closure>
* @var array<class-string<Command>, Closure>
*/
private array $bindings = [];

/**
* Bind a command handler into the container.
*
* @param string $commandClass
* @param Closure $binding
* @return void
* @param class-string<Command> $commandClass
* @param Closure(): object $binding
*/
public function bind(string $commandClass, Closure $binding): void
{
$this->bindings[$commandClass] = $binding;
}

/**
* @inheritDoc
*/
public function get(string $commandClass): CommandHandler
{
$factory = $this->bindings[$commandClass] ?? null;
Expand All @@ -48,6 +45,6 @@ public function get(string $commandClass): CommandHandler
return new CommandHandler($innerHandler);
}

throw new RuntimeException('No command handler bound for command class: ' . $commandClass);
throw new ApplicationException('No command handler bound for command class: ' . $commandClass);
}
}
8 changes: 0 additions & 8 deletions src/Application/Bus/CommandQueuer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@

class CommandQueuer implements ICommandQueuer
{
/**
* CommandQueuer constructor.
*
* @param Queue $queue
*/
public function __construct(private readonly Queue $queue)
{
}

/**
* @inheritDoc
*/
public function queue(Command $command): void
{
$this->queue->push($command);
Expand Down
8 changes: 1 addition & 7 deletions src/Application/Bus/Middleware/ExecuteInUnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@
final readonly class ExecuteInUnitOfWork implements CommandMiddleware
{
/**
* ExecuteInUnitOfWork constructor.
*
* @param UnitOfWorkManager $unitOfWorkManager
* @param int $attempts
* @param int<1, max> $attempts
*/
public function __construct(
private UnitOfWorkManager $unitOfWorkManager,
private int $attempts = 1,
) {
}

/**
* @inheritDoc
*/
public function __invoke(Command $command, Closure $next): Result
{
try {
Expand Down
8 changes: 0 additions & 8 deletions src/Application/Bus/Middleware/FlushDeferredEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,10 @@

final readonly class FlushDeferredEvents implements CommandMiddleware
{
/**
* FlushDeferredEvents constructor.
*
* @param DeferredDispatcher $dispatcher
*/
public function __construct(private DeferredDispatcher $dispatcher)
{
}

/**
* @inheritDoc
*/
public function __invoke(Command $command, Closure $next): Result
{
try {
Expand Down
11 changes: 0 additions & 11 deletions src/Application/Bus/Middleware/LogMessageDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@

final readonly class LogMessageDispatch implements BusMiddleware
{
/**
* LogMessageDispatch constructor.
*
* @param LoggerInterface $logger
* @param string $dispatchLevel
* @param string $dispatchedLevel
* @param ContextFactory $context
*/
public function __construct(
private LoggerInterface $logger,
private string $dispatchLevel = LogLevel::DEBUG,
Expand All @@ -41,9 +33,6 @@ public function __construct(
) {
}

/**
* @inheritDoc
*/
public function __invoke(Command|Query $message, Closure $next): Result
{
$name = ModuleBasename::tryFrom($message)?->toString() ?? $message::class;
Expand Down
5 changes: 0 additions & 5 deletions src/Application/Bus/Middleware/SetupBeforeDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@
final readonly class SetupBeforeDispatch implements BusMiddleware
{
/**
* SetupBeforeDispatch constructor.
*
* @param Closure(): ?Closure(): void $callback
*/
public function __construct(private Closure $callback)
{
}

/**
* @inheritDoc
*/
public function __invoke(Command|Query $message, Closure $next): Result
{
$tearDown = ($this->callback)();
Expand Down
5 changes: 0 additions & 5 deletions src/Application/Bus/Middleware/TearDownAfterDispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@
final readonly class TearDownAfterDispatch implements BusMiddleware
{
/**
* TearDownAfterDispatch constructor.
*
* @param Closure(): void $callback
*/
public function __construct(private Closure $callback)
{
}

/**
* @inheritDoc
*/
public function __invoke(Command|Query $message, Closure $next): Result
{
try {
Expand Down
10 changes: 1 addition & 9 deletions src/Application/Bus/Middleware/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,14 @@ abstract class ValidateCommand implements CommandMiddleware
/**
* Get the rules for the validation.
*
* @return iterable<string|callable>
* @return iterable<callable|string>
*/
abstract protected function rules(): iterable;

/**
* ValidateCommand constructor.
*
* @param Validator $validator
*/
public function __construct(private readonly Validator $validator)
{
}

/**
* @inheritDoc
*/
public function __invoke(Command $command, Closure $next): IResult
{
$errors = $this->validator
Expand Down
10 changes: 1 addition & 9 deletions src/Application/Bus/Middleware/ValidateQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,14 @@ abstract class ValidateQuery implements QueryMiddleware
/**
* Get the rules for the validation.
*
* @return iterable<string|callable>
* @return iterable<callable|string>
*/
abstract protected function rules(): iterable;

/**
* ValidateQuery constructor.
*
* @param Validator $validator
*/
public function __construct(private readonly Validator $validator)
{
}

/**
* @inheritDoc
*/
public function __invoke(Query $query, Closure $next): IResult
{
$errors = $this->validator
Expand Down
15 changes: 2 additions & 13 deletions src/Application/Bus/QueryDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@
class QueryDispatcher implements IQueryDispatcher
{
/**
* @var array<string|callable>
* @var array<callable|string>
*/
private array $pipes = [];

/**
* QueryDispatcher constructor.
*
* @param QueryHandlerContainer $handlers
* @param PipeContainer|null $middleware
*/
public function __construct(
private readonly QueryHandlerContainer $handlers,
private readonly ?PipeContainer $middleware = null,
Expand All @@ -42,8 +36,7 @@ public function __construct(
/**
* Dispatch messages through the provided pipes.
*
* @param array<string|callable> $pipes
* @return void
* @param array<callable|string> $pipes
*/
public function through(array $pipes): void
{
Expand All @@ -52,9 +45,6 @@ public function through(array $pipes): void
$this->pipes = $pipes;
}

/**
* @inheritDoc
*/
public function dispatch(Query $query): Result
{
$pipeline = PipelineBuilder::make($this->middleware)
Expand All @@ -71,7 +61,6 @@ public function dispatch(Query $query): Result
}

/**
* @param Query $query
* @return Result<mixed>
*/
private function execute(Query $query): Result
Expand Down
11 changes: 0 additions & 11 deletions src/Application/Bus/QueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,10 @@

final readonly class QueryHandler implements IQueryHandler
{
/**
* QueryHandler constructor.
*
* @param object $handler
*/
public function __construct(private object $handler)
{
}

/**
* @inheritDoc
*/
public function __invoke(Query $query): Result
{
assert(method_exists($this->handler, 'execute'), sprintf(
Expand All @@ -46,9 +38,6 @@ public function __invoke(Query $query): Result
return $result;
}

/**
* @inheritDoc
*/
public function middleware(): array
{
if ($this->handler instanceof DispatchThroughMiddleware) {
Expand Down
Loading