Skip to content

Version 3 #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.idea
composer.lock
TestReport
vendor
.php_cs.cache
.php-cs-fixer.cache
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

19 changes: 14 additions & 5 deletions Exceptions/Collection/CollectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@

namespace Exceptions\Collection;

use Exceptions\Helpers\DefaultConstructorTrait;
use Exceptions\Helpers\DefaultsInterface;
use Exceptions\Helpers\FromException;
use Exceptions\Helpers\WithContext;
use RuntimeException;
use Throwable;

/**
* This is a tag like class that is used to regroup all Collection exceptions under a single base class.
*
* @author Mathieu Dumoulin <[email protected]>
* @license MIT
*/
abstract class CollectionException extends \RuntimeException implements CollectionExceptionInterface, DefaultsInterface
abstract class CollectionException extends RuntimeException implements CollectionExceptionInterface, DefaultsInterface
{
use FromException, DefaultConstructorTrait, WithContext;
public function __construct(
string $message = "",
int $code = 0,
null|Throwable $previous = null
) {
parent::__construct(
message: $message ?: $this->getDefaultMessage(),
code: $code ?: $this->getDefaultCode(),
previous: $previous
);
}

/**
* {@inheritdoc}
Expand Down
4 changes: 2 additions & 2 deletions Exceptions/Collection/EmptyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
*/
class EmptyException extends CollectionException
{
const MESSAGE = 'Array/collection is currently empty';
const CODE = 0;
public const MESSAGE = 'Array/collection is currently empty';
public const CODE = 0;
}
6 changes: 3 additions & 3 deletions Exceptions/Collection/FullException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

/**
* Use this exception when an operation on a collection cannot be achieved because the collection has already reached
* it's limit and cannot accept more data.
* its limit and cannot accept more data.
*
* @author Mathieu Dumoulin <[email protected]>
* @license MIT
*/
class FullException extends CollectionException
{
const MESSAGE = 'Cannot add items to array/collection, it is already full';
const CODE = 0;
public const MESSAGE = 'Cannot add items to array/collection, it is already full';
public const CODE = 0;
}
8 changes: 4 additions & 4 deletions Exceptions/Collection/KeyAlreadyExistsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Exceptions\Collection;

use Exceptions\Tag\ExistsTag;
use Exceptions\Tag\AlreadyExistsTag;

/**
* Use this exception when an operation on a collection tries to add an element using a key that already exists in the
Expand All @@ -11,8 +11,8 @@
* @author Mathieu Dumoulin <[email protected]>
* @license MIT
*/
class KeyAlreadyExistsException extends CollectionException implements ExistsTag
class KeyAlreadyExistsException extends CollectionException implements AlreadyExistsTag
{
const MESSAGE = 'Key already exists in array/collection';
const CODE = 0;
public const MESSAGE = 'Key already exists in array/collection';
public const CODE = 0;
}
4 changes: 2 additions & 2 deletions Exceptions/Collection/KeyNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
*/
class KeyNotFoundException extends CollectionException implements NotFoundTag
{
const MESSAGE = 'Key not found in array/collection';
const CODE = 0;
public const MESSAGE = 'Key not found in array/collection';
public const CODE = 0;
}
4 changes: 2 additions & 2 deletions Exceptions/Collection/ReadOnlyArrayException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
*/
class ReadOnlyArrayException extends CollectionException
{
const MESSAGE = 'Array/Collection is read-only, you cannot alter it';
const CODE = 0;
public const MESSAGE = 'Array/Collection is read-only, you cannot alter it';
public const CODE = 0;
}
4 changes: 2 additions & 2 deletions Exceptions/Collection/ReadOnlyArrayItemException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
*/
class ReadOnlyArrayItemException extends CollectionException
{
const MESSAGE = 'Array/Collection item is read-only, you cannot modify it';
const CODE = 0;
public const MESSAGE = 'Array/Collection item is read-only, you cannot modify it';
public const CODE = 0;
}
19 changes: 14 additions & 5 deletions Exceptions/Data/DataException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@

namespace Exceptions\Data;

use Exceptions\Helpers\DefaultConstructorTrait;
use Exceptions\Helpers\DefaultsInterface;
use Exceptions\Helpers\FromException;
use Exceptions\Helpers\WithContext;
use RuntimeException;
use Throwable;

/**
* This is a tag like class that is used to regroup all Data exceptions under a single base class.
*
* @author Mathieu Dumoulin <[email protected]>
* @license MIT
*/
abstract class DataException extends \RuntimeException implements DataExceptionInterface, DefaultsInterface
abstract class DataException extends RuntimeException implements DataExceptionInterface, DefaultsInterface
{
use FromException, DefaultConstructorTrait, WithContext;
public function __construct(
string $message = "",
int $code = 0,
null|Throwable $previous = null
) {
parent::__construct(
message: $message ?: $this->getDefaultMessage(),
code: $code ?: $this->getDefaultCode(),
previous: $previous
);
}

/**
* {@inheritdoc}
Expand Down
4 changes: 2 additions & 2 deletions Exceptions/Data/FormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/
class FormatException extends DataException implements InvalidDataTag
{
const MESSAGE = 'Data provided is not of the expected format or cannot be parsed correctly.';
const CODE = 0;
public const MESSAGE = 'Data provided is not of the expected format or cannot be parsed correctly.';
public const CODE = 0;
}
8 changes: 4 additions & 4 deletions Exceptions/Data/FoundTooLittleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Exceptions\Data;

/**
* Use this exception when the data requested by your code was found but it found actually less than expected. A
* good use for this is when you are looking for a specific set of items such as 10 items but you end up finding only
* Use this exception when the data requested by your code was found, but it found actually less than expected. A
* good use for this is when you are looking for a specific set of items such as 10 items, but you end up finding only
* 9. In this case, you throw this exception.
*
* If the code in context is a service provider that queries a database, this would be the right exception to throw
Expand All @@ -16,6 +16,6 @@
*/
class FoundTooLittleException extends DataException
{
const MESSAGE = 'Found too little items in the data source.';
const CODE = 0;
public const MESSAGE = 'Found too little items in the data source.';
public const CODE = 0;
}
6 changes: 3 additions & 3 deletions Exceptions/Data/FoundTooManyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Exceptions\Data;

/**
* Use this exception when the data requested by your code was found and it found actually more than expected. A good
* Use this exception when the data requested by your code was found, and it found actually more than expected. A good
* use for this is the findSingle usual function we find in many library and orm. If you have more than 1 record
* found, it might mean that you should send back this exception.
*
Expand All @@ -16,6 +16,6 @@
*/
class FoundTooManyException extends DataException
{
const MESSAGE = 'Found too many items in the data source.';
const CODE = 0;
public const MESSAGE = 'Found too many items in the data source.';
public const CODE = 0;
}
4 changes: 2 additions & 2 deletions Exceptions/Data/IntegrityException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
*/
class IntegrityException extends DataException implements InvalidDataTag
{
const MESSAGE = 'Data provided is not of the expected format or cannot be parsed correctly.';
const CODE = 0;
public const MESSAGE = 'Data provided is not of the expected format or cannot be parsed correctly.';
public const CODE = 0;
}
4 changes: 2 additions & 2 deletions Exceptions/Data/NotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*/
class NotFoundException extends DataException implements NotFoundTag
{
const MESSAGE = 'Data requested for cannot be found in the data source.';
const CODE = 0;
public const MESSAGE = 'Data requested for cannot be found in the data source.';
public const CODE = 0;
}
4 changes: 2 additions & 2 deletions Exceptions/Data/TypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
*/
class TypeException extends DataException implements InvalidDataTag
{
const MESSAGE = 'Type of the data is incorrect';
const CODE = 0;
public const MESSAGE = 'Type of the data is incorrect';
public const CODE = 0;
}
4 changes: 2 additions & 2 deletions Exceptions/Data/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*/
class ValidationException extends DataException implements InvalidDataTag
{
const MESSAGE = 'Provided data does not conform to business model or basic domain validation rules';
const CODE = 0;
public const MESSAGE = 'Provided data does not conform to business model or basic domain validation rules';
public const CODE = 0;
}
4 changes: 2 additions & 2 deletions Exceptions/Http/Client/BadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class BadRequestException extends ClientErrorException implements InvalidDataTag
/**
* Returns the HTTP error code for that exception.
*/
const HTTP_CODE = 400;
public const HTTP_CODE = 400;

/**
* Returns the HTTP error message for that exception.
*/
const HTTP_MESSAGE = 'Bad Request: The request could not be understood by the server due to malformed syntax. The client should not repeat the request without modifications.';
public const HTTP_MESSAGE = 'Bad Request: The request could not be understood by the server due to malformed syntax. The client should not repeat the request without modifications.';
}
5 changes: 2 additions & 3 deletions Exceptions/Http/Client/ClientErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
namespace Exceptions\Http\Client;

use Exceptions\Http\HttpException;
use Exceptions\Tag\AbortedTag;

/**
* This is a tag like class that is used to regroup all Http/Client exceptions under a single base class.
*
* Never throw an exception at the user, always catch it can synthesize it to a correct html response with
* appropriate headers. You can use the constants and accessor to get HTML values to return.
*/
abstract class ClientErrorException extends HttpException implements ClientErrorExceptionInterface, AbortedTag
abstract class ClientErrorException extends HttpException implements ClientErrorExceptionInterface
{
/**
* {@inheritdoc}
*/
public static function getHttpCodeClass()
public static function getHttpCodeClass(): int
{
return self::CODE_CLASS_CLIENT_ERROR;
}
Expand Down
4 changes: 2 additions & 2 deletions Exceptions/Http/Client/ConflictException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class ConflictException extends ClientErrorException implements InvalidDataTag
/**
* Returns the HTTP error code for that exception.
*/
const HTTP_CODE = 409;
public const HTTP_CODE = 409;

/**
* Returns the HTTP error message for that exception.
*/
const HTTP_MESSAGE = 'Conflict: The request could not be completed due to a conflict with the current state of the resource. Fix the errors that are producing the conflict and then try again. This error is often caused by desynchronized states between client and server, something changed on one or the other and the resources are out of sync.';
public const HTTP_MESSAGE = 'Conflict: The request could not be completed due to a conflict with the current state of the resource. Fix the errors that are producing the conflict and then try again. This error is often caused by desynchronized states between client and server, something changed on one or the other and the resources are out of sync.';
}
6 changes: 3 additions & 3 deletions Exceptions/Http/Client/ExpectationFailedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Exceptions\Tag\InvalidDataTag;

/**
* The request could not be completed because the request specified a "Expect" request header that the server cannot
* The request could not be completed because the request specified an "Expect" request header that the server cannot
* fulfill.
*
* Never throw an exception at the user, always catch it can synthesize it to a correct html response with
Expand All @@ -19,10 +19,10 @@ class ExpectationFailedException extends ClientErrorException implements Invalid
/**
* Returns the HTTP error code for that exception.
*/
const HTTP_CODE = 417;
public const HTTP_CODE = 417;

/**
* Returns the HTTP error message for that exception.
*/
const HTTP_MESSAGE = 'Expectation Failed: The request cannot be completed because the request you are making contains an Expect header that the server cannot fulfill.';
public const HTTP_MESSAGE = 'Expectation Failed: The request cannot be completed because the request you are making contains an Expect header that the server cannot fulfill.';
}
4 changes: 2 additions & 2 deletions Exceptions/Http/Client/FailedDependencyException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class FailedDependencyException extends ClientErrorException
/**
* Returns the HTTP error code for that exception.
*/
const HTTP_CODE = 424;
public const HTTP_CODE = 424;

/**
* Returns the HTTP error message for that exception.
*/
const HTTP_MESSAGE = 'Failed Dependency: The request cannot be completed because an underlying process failed to complete properly or there is a dependency that cannot be met around the process.';
public const HTTP_MESSAGE = 'Failed Dependency: The request cannot be completed because an underlying process failed to complete properly or there is a dependency that cannot be met around the process.';
}
4 changes: 2 additions & 2 deletions Exceptions/Http/Client/ForbiddenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ForbiddenException extends ClientErrorException implements ForbiddenTag
/**
* Returns the HTTP error code for that exception.
*/
const HTTP_CODE = 403;
public const HTTP_CODE = 403;

/**
* Returns the HTTP error message for that exception.
*/
const HTTP_MESSAGE = 'Forbidden: The server understood the request, but is refusing to fulfill it. Authorization will not help and the request should not be repeated.';
public const HTTP_MESSAGE = 'Forbidden: The server understood the request, but is refusing to fulfill it. Authorization will not help and the request should not be repeated.';
}
4 changes: 2 additions & 2 deletions Exceptions/Http/Client/GoneException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class GoneException extends ClientErrorException implements NotFoundTag
/**
* Returns the HTTP error code for that exception.
*/
const HTTP_CODE = 410;
public const HTTP_CODE = 410;

/**
* Returns the HTTP error message for that exception.
*/
const HTTP_MESSAGE = 'Gone: The request cannot be completed because the resource you are requesting has been moved or has changed state.';
public const HTTP_MESSAGE = 'Gone: The request cannot be completed because the resource you are requesting has been moved or has changed state.';
}
28 changes: 0 additions & 28 deletions Exceptions/Http/Client/ImATeapotException.php

This file was deleted.

Loading