Skip to content

Commit

Permalink
Merge pull request #30 from Jeckel-Lab/feature/rework-exceptions
Browse files Browse the repository at this point in the history
Feature/rework exceptions
  • Loading branch information
jeckel authored Jan 3, 2022
2 parents 45f2d61 + af7d9b7 commit bf4758d
Show file tree
Hide file tree
Showing 26 changed files with 54 additions and 190 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ $speed1 === $speed2; // is true
> See detailed implementation proposal: [jeckel-lab/query-dispatcher](https://github.com/Jeckel-Lab/query-dispatcher)
## Exceptions

Each layer has it's own Exception interface that extends `Throwable`:

- Core: [CoreException](src/Core/Exception/CoreException.php)
- Domain: [DomainException](src/Domain/Exception/DomainException.php)
- Infrastructure: [InfrastructureException](src/Infrastructure/Exception/InfrastructureException.php)
- Presentation: [PresentationException](src/Presentation/Exception/PresentationException.php)

In each layer, when we need to throw an Exception, we create a new class corresponding to the type of Exception. This class must:

- extends one of the [SPL exception](https://www.php.net/manual/en/spl.exceptions.php) or another (more generic) exception from the same namespace.
- implements the exception interface of the current layer.


## Old Documentation

### Core
Expand Down
2 changes: 2 additions & 0 deletions src/Core/CommandDispatcher/CommandBus/CommandBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse;
use JeckelLab\Contract\Core\CommandDispatcher\Exception\NoHandlerDefinedForCommandException;

/**
* Interface CommandBus
Expand All @@ -19,6 +20,7 @@ interface CommandBus
/**
* @param Command $command
* @return CommandResponse
* @throws NoHandlerDefinedForCommandException
*/
public function dispatch(Command $command): CommandResponse;
}

This file was deleted.

4 changes: 2 additions & 2 deletions src/Core/CommandDispatcher/CommandHandler/CommandHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
use JeckelLab\Contract\Core\CommandDispatcher\CommandResponse\CommandResponse;
use JeckelLab\Contract\Core\CommandDispatcher\Exception\InvalidCommandException;
use JeckelLab\Contract\Core\CommandDispatcher\Exception\InvalidCommandTypeException;

/**
* Interface CommandHandler
Expand All @@ -27,7 +27,7 @@ public static function getHandledCommands(): array;
/**
* @param CommandType $command
* @return CommandResponse
* @throws InvalidCommandException
* @throws InvalidCommandTypeException
*/
public function __invoke(Command $command): CommandResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace JeckelLab\Contract\Core\CommandDispatcher\Exception;

use JeckelLab\Contract\Core\Exception\CoreMainException;
use JeckelLab\Contract\Core\Exception\CoreException;

/**
* Interface CommandDispatcherException
* @package JeckelLab\Contract\Core\CommandDispatcher\Exception
* @psalm-immutable
*/
interface CommandDispatcherException extends CoreMainException
interface CommandDispatcherException extends CoreException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

namespace JeckelLab\Contract\Core\CommandDispatcher\Exception;

use JeckelLab\Contract\Core\Exception\RuntimeException;
use LogicException;

/**
* Class InvalidCommandException
* @package JeckelLab\Contract\Core\CommandDispatcher\Exception
* @psalm-immutable
* @psalm-suppress MutableDependency
*/
class InvalidCommandException extends RuntimeException implements CommandDispatcherException
class InvalidCommandTypeException extends LogicException implements CommandDispatcherException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

declare(strict_types=1);

namespace JeckelLab\Contract\Core\CommandDispatcher\CommandBus\Exception;
namespace JeckelLab\Contract\Core\CommandDispatcher\Exception;

use JeckelLab\Contract\Core\CommandDispatcher\Command\Command;
use JeckelLab\Contract\Core\Exception\LogicException;
use LogicException;

/**
* Class NoHandlerDefinedForCommandException
* @package JeckelLab\Contract\Core\CommandDispatcher\CommandBus\Exception
* @package JeckelLab\Contract\Core\CommandDispatcher\Exception
* @psalm-immutable
* @psalm-suppress MutableDependency
*/
class NoHandlerDefinedForCommandException extends LogicException implements CommandBusException
class NoHandlerDefinedForCommandException extends LogicException implements CommandDispatcherException
{
/**
* @param Command $command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace JeckelLab\Contract\Core\Exception;

use JeckelLab\Contract\Exception\MainException;
use Throwable;

/**
* Interface CoreMainException
* @package JeckelLab\Contract\Core\Exception
* @psalm-immutable
*/
interface CoreMainException extends MainException
interface CoreException extends Throwable
{
}
20 changes: 0 additions & 20 deletions src/Core/Exception/LogicException.php

This file was deleted.

20 changes: 0 additions & 20 deletions src/Core/Exception/RuntimeException.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

namespace JeckelLab\Contract\Core\QueryDispatcher\Exception;

use JeckelLab\Contract\Core\Exception\RuntimeException;
use LogicException;

/**
* Class InvalidQueryException
* @package JeckelLab\Contract\Core\QueryDispatcher\Exception
* @psalm-immutable
* @psalm-suppress MutableDependency
*/
class InvalidQueryException extends RuntimeException implements QueryDispatcherException
class InvalidQueryTypeException extends LogicException implements QueryDispatcherException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

declare(strict_types=1);

namespace JeckelLab\Contract\Core\QueryDispatcher\QueryBus\Exception;
namespace JeckelLab\Contract\Core\QueryDispatcher\Exception;

use JeckelLab\Contract\Core\Exception\LogicException;
use JeckelLab\Contract\Core\QueryDispatcher\Query\Query;
use LogicException;

/**
* Class NoHandlerDefinedForQueryException
* @package JeckelLab\Contract\Core\QueryDispatcher\QueryBus\Exception
* @package JeckelLab\Contract\Core\QueryDispatcher\Exception
* @psalm-immutable
* @psalm-suppress MutableDependency
*/
class NoHandlerDefinedForQueryException extends LogicException implements QueryBusException
class NoHandlerDefinedForQueryException extends LogicException implements QueryDispatcherException
{
/**
* @param Query $query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

namespace JeckelLab\Contract\Core\QueryDispatcher\Exception;

use JeckelLab\Contract\Core\Exception\CoreMainException;
use JeckelLab\Contract\Core\Exception\CoreException;

/**
* Interface QueryDispatcherException
* @package JeckelLab\Contract\Core\QueryDispatcher\Exception
* @psalm-immutable
*/
interface QueryDispatcherException extends CoreMainException
interface QueryDispatcherException extends CoreException
{
}
19 changes: 0 additions & 19 deletions src/Core/QueryDispatcher/QueryBus/Exception/QueryBusException.php

This file was deleted.

2 changes: 2 additions & 0 deletions src/Core/QueryDispatcher/QueryBus/QueryBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace JeckelLab\Contract\Core\QueryDispatcher\QueryBus;

use JeckelLab\Contract\Core\QueryDispatcher\Exception\NoHandlerDefinedForQueryException;
use JeckelLab\Contract\Core\QueryDispatcher\Query\Query;
use JeckelLab\Contract\Core\QueryDispatcher\ViewModel\ViewModel;

Expand All @@ -15,6 +16,7 @@ interface QueryBus
/**
* @param Query $query
* @return ViewModel
* @throws NoHandlerDefinedForQueryException
*/
public function dispatch(Query $query): ViewModel;
}
4 changes: 2 additions & 2 deletions src/Core/QueryDispatcher/QueryHandler/QueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace JeckelLab\Contract\Core\QueryDispatcher\QueryHandler;

use JeckelLab\Contract\Core\QueryDispatcher\Exception\InvalidQueryException;
use JeckelLab\Contract\Core\QueryDispatcher\Exception\InvalidQueryTypeException;
use JeckelLab\Contract\Core\QueryDispatcher\Query\Query;
use JeckelLab\Contract\Core\QueryDispatcher\ViewModel\ViewModel;

Expand All @@ -22,7 +22,7 @@ public static function getHandledQueries(): array;
/**
* @param Query $query
* @return ViewModel
* @throws InvalidQueryException
* @throws InvalidQueryTypeException
*/
public function __invoke(Query $query): ViewModel;
}
20 changes: 0 additions & 20 deletions src/Domain/Exception/InvalidArgumentException.php

This file was deleted.

20 changes: 0 additions & 20 deletions src/Domain/Exception/LogicException.php

This file was deleted.

20 changes: 0 additions & 20 deletions src/Domain/Exception/RuntimeException.php

This file was deleted.

3 changes: 2 additions & 1 deletion src/Domain/Identity/Exception/InvalidIdException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace JeckelLab\Contract\Domain\Identity\Exception;

use JeckelLab\Contract\Domain\Exception\InvalidArgumentException;
use InvalidArgumentException;

/**
* Class InvalidIdException
Expand All @@ -18,6 +18,7 @@
*
* @package JeckelLab\Contract\Domain\Identity\Exception
* @psalm-immutable
* @psalm-suppress MutableDependency
*/
class InvalidIdException extends InvalidArgumentException implements IdentityException
{
Expand Down
5 changes: 3 additions & 2 deletions src/Domain/ValueObject/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@

namespace JeckelLab\Contract\Domain\ValueObject\Exception;

use JeckelLab\Contract\Domain\Exception\InvalidArgumentException as DomainInvalidArgumentException;
use InvalidArgumentException as InvalidArgumentExceptionCore;

/**
* Class InvalidArgumentException
* @package ValueObject\Exception
* @psalm-immutable
* @psalm-suppress MutableDependency
*/
class InvalidArgumentException extends DomainInvalidArgumentException implements ValueObjectException
class InvalidArgumentException extends InvalidArgumentExceptionCore implements ValueObjectException
{
}
Loading

0 comments on commit bf4758d

Please sign in to comment.