Skip to content

Commit bf4758d

Browse files
authored
Merge pull request #30 from Jeckel-Lab/feature/rework-exceptions
Feature/rework exceptions
2 parents 45f2d61 + af7d9b7 commit bf4758d

File tree

26 files changed

+54
-190
lines changed

26 files changed

+54
-190
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,21 @@ $speed1 === $speed2; // is true
192192
193193
> See detailed implementation proposal: [jeckel-lab/query-dispatcher](https://github.com/Jeckel-Lab/query-dispatcher)
194194
195+
## Exceptions
196+
197+
Each layer has it's own Exception interface that extends `Throwable`:
198+
199+
- Core: [CoreException](src/Core/Exception/CoreException.php)
200+
- Domain: [DomainException](src/Domain/Exception/DomainException.php)
201+
- Infrastructure: [InfrastructureException](src/Infrastructure/Exception/InfrastructureException.php)
202+
- Presentation: [PresentationException](src/Presentation/Exception/PresentationException.php)
203+
204+
In each layer, when we need to throw an Exception, we create a new class corresponding to the type of Exception. This class must:
205+
206+
- extends one of the [SPL exception](https://www.php.net/manual/en/spl.exceptions.php) or another (more generic) exception from the same namespace.
207+
- implements the exception interface of the current layer.
208+
209+
195210
## Old Documentation
196211

197212
### Core

src/Core/CommandDispatcher/CommandBus/CommandBus.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
1111
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse;
12+
use JeckelLab\Contract\Core\CommandDispatcher\Exception\NoHandlerDefinedForCommandException;
1213

1314
/**
1415
* Interface CommandBus
@@ -19,6 +20,7 @@ interface CommandBus
1920
/**
2021
* @param Command $command
2122
* @return CommandResponse
23+
* @throws NoHandlerDefinedForCommandException
2224
*/
2325
public function dispatch(Command $command): CommandResponse;
2426
}

src/Core/CommandDispatcher/CommandBus/Exception/CommandBusException.php

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

src/Core/CommandDispatcher/CommandHandler/CommandHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
1111
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse;
12-
use JeckelLab\Contract\Core\CommandDispatcher\Exception\InvalidCommandException;
12+
use JeckelLab\Contract\Core\CommandDispatcher\Exception\InvalidCommandTypeException;
1313

1414
/**
1515
* Interface CommandHandler
@@ -27,7 +27,7 @@ public static function getHandledCommands(): array;
2727
/**
2828
* @param CommandType $command
2929
* @return CommandResponse
30-
* @throws InvalidCommandException
30+
* @throws InvalidCommandTypeException
3131
*/
3232
public function __invoke(Command $command): CommandResponse;
3333
}

src/Core/CommandDispatcher/Exception/CommandDispatcherException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
namespace JeckelLab\Contract\Core\CommandDispatcher\Exception;
99

10-
use JeckelLab\Contract\Core\Exception\CoreMainException;
10+
use JeckelLab\Contract\Core\Exception\CoreException;
1111

1212
/**
1313
* Interface CommandDispatcherException
1414
* @package JeckelLab\Contract\Core\CommandDispatcher\Exception
1515
* @psalm-immutable
1616
*/
17-
interface CommandDispatcherException extends CoreMainException
17+
interface CommandDispatcherException extends CoreException
1818
{
1919
}

src/Core/CommandDispatcher/Exception/InvalidCommandException.php renamed to src/Core/CommandDispatcher/Exception/InvalidCommandTypeException.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
namespace JeckelLab\Contract\Core\CommandDispatcher\Exception;
1111

12-
use JeckelLab\Contract\Core\Exception\RuntimeException;
12+
use LogicException;
1313

1414
/**
1515
* Class InvalidCommandException
1616
* @package JeckelLab\Contract\Core\CommandDispatcher\Exception
1717
* @psalm-immutable
18+
* @psalm-suppress MutableDependency
1819
*/
19-
class InvalidCommandException extends RuntimeException implements CommandDispatcherException
20+
class InvalidCommandTypeException extends LogicException implements CommandDispatcherException
2021
{
2122
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77

88
declare(strict_types=1);
99

10-
namespace JeckelLab\Contract\Core\CommandDispatcher\CommandBus\Exception;
10+
namespace JeckelLab\Contract\Core\CommandDispatcher\Exception;
1111

1212
use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
13-
use JeckelLab\Contract\Core\Exception\LogicException;
13+
use LogicException;
1414

1515
/**
1616
* Class NoHandlerDefinedForCommandException
17-
* @package JeckelLab\Contract\Core\CommandDispatcher\CommandBus\Exception
17+
* @package JeckelLab\Contract\Core\CommandDispatcher\Exception
1818
* @psalm-immutable
19+
* @psalm-suppress MutableDependency
1920
*/
20-
class NoHandlerDefinedForCommandException extends LogicException implements CommandBusException
21+
class NoHandlerDefinedForCommandException extends LogicException implements CommandDispatcherException
2122
{
2223
/**
2324
* @param Command $command

src/Core/Exception/CoreMainException.php renamed to src/Core/Exception/CoreException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
namespace JeckelLab\Contract\Core\Exception;
99

10-
use JeckelLab\Contract\Exception\MainException;
10+
use Throwable;
1111

1212
/**
1313
* Interface CoreMainException
1414
* @package JeckelLab\Contract\Core\Exception
1515
* @psalm-immutable
1616
*/
17-
interface CoreMainException extends MainException
17+
interface CoreException extends Throwable
1818
{
1919
}

src/Core/Exception/LogicException.php

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

src/Core/Exception/RuntimeException.php

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

0 commit comments

Comments
 (0)