Skip to content

Commit 8f66f06

Browse files
authored
Merge pull request #24 from Jeckel-Lab/feature/upgrade-to-jeckel-lab-contract
Feature/upgrade to jeckel lab contract
2 parents 9920182 + eecacab commit 8f66f06

20 files changed

+125
-285
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"require": {
2323
"php": "^7.2",
2424
"psr/event-dispatcher": "^1.0",
25-
"psr/container": "^1.0"
25+
"psr/container": "^1.0",
26+
"jeckel-lab/contract": "0.1"
2627
},
2728
"require-dev": {
2829
"phpunit/phpunit": "^8.4",

src/Command/CommandInterface.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/CommandBus/CommandBusInterface.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/CommandBus/CommandDispatcher.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99

1010
namespace JeckelLab\CommandDispatcher\CommandBus;
1111

12-
use JeckelLab\CommandDispatcher\Command\CommandInterface;
13-
use JeckelLab\CommandDispatcher\CommandHandler\CommandHandlerInterface;
14-
use JeckelLab\CommandDispatcher\CommandResponse\CommandResponseInterface;
1512
use JeckelLab\CommandDispatcher\Resolver\CommandHandlerResolverInterface;
13+
use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
14+
use JeckelLab\Contract\Core\CommandDispatcher\CommandBus\CommandBus;
15+
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse;
1616

1717
/**
1818
* Class CommandDispatcher
1919
* @package JeckelLab\CommandDispatcher\CommandBus
2020
*/
21-
class CommandDispatcher implements CommandBusInterface
21+
class CommandDispatcher implements CommandBus
2222
{
2323
/**
2424
* @var CommandHandlerResolverInterface
@@ -36,18 +36,13 @@ public function __construct(
3636
}
3737

3838
/**
39-
* @param CommandInterface $command
40-
* @return CommandResponseInterface
39+
* @param Command $command
40+
* @return CommandResponse
4141
* @SuppressWarnings(PHPMD.IfStatementAssignment)
4242
*/
43-
public function dispatch(CommandInterface $command): CommandResponseInterface
43+
public function dispatch(Command $command): CommandResponse
4444
{
45-
/** @var CommandHandlerInterface $handler */
4645
$handler = $this->resolver->resolve($command);
47-
48-
/** @var CommandResponseInterface $response */
49-
$response = $handler($command);
50-
51-
return $response;
46+
return $handler($command);
5247
}
5348
}

src/CommandBus/EventDispatcherDecorator.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,39 @@
99

1010
namespace JeckelLab\CommandDispatcher\CommandBus;
1111

12-
use JeckelLab\CommandDispatcher\Command\CommandInterface;
13-
use JeckelLab\CommandDispatcher\CommandResponse\CommandResponseInterface;
12+
use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
13+
use JeckelLab\Contract\Core\CommandDispatcher\CommandBus\CommandBus;
14+
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse;
1415
use Psr\EventDispatcher\EventDispatcherInterface;
1516

1617
/**
1718
* Class EventDispatcherDecorator
1819
* @package JeckelLab\CommandDispatcher\CommandBus
1920
*/
20-
class EventDispatcherDecorator implements CommandBusInterface
21+
class EventDispatcherDecorator implements CommandBus
2122
{
2223
/** @var EventDispatcherInterface */
2324
protected $eventDispatcher;
2425

25-
/** @var CommandBusInterface */
26+
/** @var CommandBus */
2627
protected $next;
2728

2829
/**
2930
* EventDispatcherDecorator constructor.
3031
* @param EventDispatcherInterface $eventDispatcher
31-
* @param CommandBusInterface $next
32+
* @param CommandBus $next
3233
*/
33-
public function __construct(EventDispatcherInterface $eventDispatcher, CommandBusInterface $next)
34+
public function __construct(EventDispatcherInterface $eventDispatcher, CommandBus $next)
3435
{
3536
$this->eventDispatcher = $eventDispatcher;
3637
$this->next = $next;
3738
}
3839

3940
/**
40-
* @param CommandInterface $command
41-
* @return CommandResponseInterface
41+
* @param Command $command
42+
* @return CommandResponse
4243
*/
43-
public function dispatch(CommandInterface $command): CommandResponseInterface
44+
public function dispatch(Command $command): CommandResponse
4445
{
4546
$response = $this->next->dispatch($command);
4647

src/CommandDispatcher.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
<?php
2-
declare(strict_types=1);
2+
33
/**
44
* @author Julien Mercier-Rojas <julien@jeckel-lab.fr>
55
* Created at : 27/10/2019
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace JeckelLab\CommandDispatcher;
911

10-
use JeckelLab\CommandDispatcher\Command\CommandInterface;
11-
use JeckelLab\CommandDispatcher\CommandHandler\CommandHandlerInterface;
12-
use JeckelLab\CommandDispatcher\CommandResponse\CommandResponseInterface;
1312
use JeckelLab\CommandDispatcher\Resolver\CommandHandlerResolverInterface;
13+
use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
14+
use JeckelLab\Contract\Core\CommandDispatcher\CommandBus\CommandBus;
15+
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse;
1416
use Psr\EventDispatcher\EventDispatcherInterface;
1517

1618
/**
1719
* Class CommandDispatcher
1820
* @package JeckelLab\CommandDispatcher
1921
*/
20-
class CommandDispatcher implements CommandDispatcherInterface
22+
class CommandDispatcher implements CommandBus
2123
{
2224
/**
2325
* @var CommandHandlerResolverInterface
@@ -43,16 +45,13 @@ public function __construct(
4345
}
4446

4547
/**
46-
* @param CommandInterface $command
47-
* @return CommandResponseInterface
48+
* @param Command $command
49+
* @return CommandResponse
4850
* @SuppressWarnings(PHPMD.IfStatementAssignment)
4951
*/
50-
public function dispatch(CommandInterface $command): CommandResponseInterface
52+
public function dispatch(Command $command): CommandResponse
5153
{
52-
/** @var CommandHandlerInterface $handler */
5354
$handler = $this->resolver->resolve($command);
54-
55-
/** @var CommandResponseInterface $response */
5655
$response = $handler($command);
5756

5857
if (null !== $this->eventDispatcher && null !== ($events = $response->getEvents())) {

src/CommandDispatcherInterface.php

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
<?php
2-
declare(strict_types=1);
2+
33
/**
44
* @author Julien Mercier-Rojas <julien@jeckel-lab.fr>
55
* Created at : 14/11/2019
66
*/
77

8+
declare(strict_types=1);
9+
810
namespace JeckelLab\CommandDispatcher\CommandHandler;
911

10-
use JeckelLab\CommandDispatcher\Command\CommandInterface;
11-
use JeckelLab\CommandDispatcher\CommandResponse\CommandResponse;
12-
use JeckelLab\CommandDispatcher\CommandResponse\CommandResponseInterface;
1312
use JeckelLab\CommandDispatcher\Exception\InvalidCommandException;
13+
use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
14+
use JeckelLab\Contract\Core\CommandDispatcher\CommandHandler\CommandHandler;
15+
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse;
1416

1517
/**
1618
* Class CommandHandlerAbstract
1719
* @package JeckelLab\CommandDispatcher\CommandHandler
1820
*/
19-
abstract class CommandHandlerAbstract implements CommandHandlerInterface
21+
abstract class CommandHandlerAbstract implements CommandHandler
2022
{
2123
/**
22-
* @param CommandInterface $command
24+
* @param Command $command
2325
* @throws InvalidCommandException
2426
*/
25-
protected function validateCommand(CommandInterface $command): void
27+
protected function validateCommand(Command $command): void
2628
{
2729
foreach (static::getHandledCommands() as $handledCommand) {
2830
if ($command instanceof $handledCommand) {
@@ -36,23 +38,19 @@ protected function validateCommand(CommandInterface $command): void
3638
}
3739

3840
/**
39-
* @param CommandInterface $command
40-
* @return CommandResponseInterface
41+
* @param Command $command
42+
* @return CommandResponse
4143
*/
42-
public function __invoke(CommandInterface $command): CommandResponseInterface
44+
public function __invoke(Command $command): CommandResponse
4345
{
4446
$this->validateCommand($command);
4547

46-
return $this->process($command, new CommandResponse());
48+
return $this->process($command);
4749
}
4850

4951
/**
50-
* @param CommandInterface $command
51-
* @param CommandResponseInterface $commandResponse
52-
* @return CommandResponseInterface
52+
* @param Command $command
53+
* @return CommandResponse
5354
*/
54-
abstract protected function process(
55-
CommandInterface $command,
56-
CommandResponseInterface $commandResponse
57-
): CommandResponseInterface;
55+
abstract protected function process(Command $command): CommandResponse;
5856
}

src/CommandHandler/CommandHandlerInterface.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/CommandResponse/CommandResponse.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
namespace JeckelLab\CommandDispatcher\CommandResponse;
99

10+
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse as CommandResponseInterface;
11+
use JeckelLab\Contract\Domain\Event\Event;
12+
1013
/**
1114
* Class CommandResponse
1215
* @package JeckelLab\CommandDispatcher\CommandResponse
16+
* @psalm-immutable
1317
*/
1418
class CommandResponse implements CommandResponseInterface
1519
{
@@ -19,7 +23,7 @@ class CommandResponse implements CommandResponseInterface
1923
/**
2024
* CommandResponseAbstract constructor.
2125
* @param bool $ack
22-
* @param iterable<mixed>|null $events
26+
* @param iterable<Event>|null $events
2327
*
2428
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
2529
*/

0 commit comments

Comments
 (0)