Skip to content

Commit

Permalink
feat(master): Add exception levels
Browse files Browse the repository at this point in the history
- Add ExceptionLevelsInterface
- Add ExceptionLevelsTrait
- Update Exceptions
  • Loading branch information
Artem O. Architect committed Feb 19, 2021
1 parent 96dca89 commit 2a8ba29
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/Domain/Exception/AlertException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*
* @category Exception
*/
class AlertException extends Exception
class AlertException extends Exception implements ExceptionLevelsInterface, ParentExceptionInterface
{
use ParentExceptionTrait;
protected string $level = self::EXCEPTION_LEVEL_ALERT;

use ParentExceptionTrait, ExceptionLevelsTrait;
}
6 changes: 4 additions & 2 deletions src/Domain/Exception/CriticalException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*
* @category Exception
*/
class CriticalException extends Exception
class CriticalException extends Exception implements ExceptionLevelsInterface, ParentExceptionInterface
{
use ParentExceptionTrait;
protected string $level = self::EXCEPTION_LEVEL_CRITICAL;

use ParentExceptionTrait, ExceptionLevelsTrait;
}
6 changes: 4 additions & 2 deletions src/Domain/Exception/EmergencyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
*
* @category Exception
*/
class EmergencyException extends Exception
class EmergencyException extends Exception implements ExceptionLevelsInterface, ParentExceptionInterface
{
use ParentExceptionTrait;
protected string $level = self::EXCEPTION_LEVEL_EMERGENCY;

use ParentExceptionTrait, ExceptionLevelsTrait;
}
4 changes: 2 additions & 2 deletions src/Domain/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @category Exception
*/
class ErrorException extends Exception
class ErrorException extends Exception implements ExceptionLevelsInterface, ParentExceptionInterface
{
use ParentExceptionTrait;
use ParentExceptionTrait, ExceptionLevelsTrait;
}
25 changes: 25 additions & 0 deletions src/Domain/Exception/ExceptionLevelsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace MicroModule\Base\Domain\Exception;

use Throwable;

/**
* Interface ExceptionLevelsInterface.
*
* @category Exception
*/
interface ExceptionLevelsInterface
{
public const EXCEPTION_LEVEL_EMERGENCY = 'emergency';
public const EXCEPTION_LEVEL_ALERT = 'alert';
public const EXCEPTION_LEVEL_CRITICAL = 'critical';
public const EXCEPTION_LEVEL_ERROR = 'error';

/**
* Return exception level const.
*/
public function getExceptionLevel(): string;
}
28 changes: 28 additions & 0 deletions src/Domain/Exception/ExceptionLevelsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace MicroModule\Base\Domain\Exception;

use Throwable;

/**
* Trait ParentExceptionTrait.
*
* @category Exception
*/
trait ExceptionLevelsTrait
{
/**
* Exception level.
*/
protected string $levels = ExceptionLevelsInterface::EXCEPTION_LEVEL_ERROR;

/**
* Return exception level const.
*/
public function getExceptionLevel(): string
{
return $this->levels;
}
}
2 changes: 1 addition & 1 deletion src/Domain/Exception/FactoryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*
* @category Domain\Exception
*/
final class FactoryException extends CriticalException
class FactoryException extends CriticalException
{
}
2 changes: 1 addition & 1 deletion src/Domain/Exception/InvalidDataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*
* @category Domain\Exception
*/
final class InvalidDataException extends ErrorException
class InvalidDataException extends ErrorException
{
}
2 changes: 1 addition & 1 deletion src/Domain/Exception/InvalidDataTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*
* @category Domain\Exception
*/
final class InvalidDataTypeException extends ErrorException
class InvalidDataTypeException extends ErrorException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*
* @category Domain\Exception
*/
final class InvalidResponseContentTypeException extends CriticalException
class InvalidResponseContentTypeException extends CriticalException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*
* @category Domain\Exception
*/
final class InvalidResponseStatusCodeException extends CriticalException
class InvalidResponseStatusCodeException extends CriticalException
{
}
2 changes: 1 addition & 1 deletion src/Domain/Exception/InvalidResponseStatusException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*
* @category Domain\Exception
*/
final class InvalidResponseStatusException extends CriticalException
class InvalidResponseStatusException extends CriticalException
{
}
2 changes: 1 addition & 1 deletion src/Domain/Exception/LoggerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
*
* @category Domain\Exception
*/
final class LoggerException extends ErrorException
class LoggerException extends ErrorException
{
}

0 comments on commit 2a8ba29

Please sign in to comment.