Skip to content

Commit 042dc79

Browse files
authored
Too many found exception (#6)
* Added the FoundTooManyException * Update of README.md
1 parent df97b82 commit 042dc79

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Exceptions\Data;
4+
5+
/**
6+
* Use this exception when the data requested by your code was found and it found actually more than expected. A good
7+
* use for this is the findSingle usual function we find in many library and orm. If you have more than 1 record
8+
* found, it might mean that you should send back this exception.
9+
*
10+
* If the code in context is a service provider that queries a database, this would be the right exception to throw
11+
* and listen for. The controller on the other hand would catch this and throw a NotFoundException from the Http
12+
* namespace which would be converted to a standardized message in the front controller.
13+
*
14+
* @author Mathieu Dumoulin aka CrazyCodr <[email protected]>
15+
* @license MIT
16+
*/
17+
class FoundTooManyException extends DataException
18+
{
19+
public function __construct(
20+
$message = 'Found too many items in the data source.',
21+
$code = 0,
22+
$previous = null
23+
) {
24+
parent::__construct($message, $code, $previous);
25+
}
26+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Data exceptions pertain to all the validation aspect of data and the operations
5858
- FormatException
5959
- IntegrityException
6060
- NotFoundException
61+
- TooManyFoundException
6162
- TypeException
6263
- ValidationException
6364

Tests/ExceptionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function providesConstructorTestClasses()
1717
[\Exceptions\Data\FormatException::class],
1818
[\Exceptions\Data\IntegrityException::class],
1919
[\Exceptions\Data\NotFoundException::class],
20+
[\Exceptions\Data\FoundTooManyException::class],
2021
[\Exceptions\Data\TypeException::class],
2122
[\Exceptions\Data\ValidationException::class],
2223
[\Exceptions\Http\Client\BadRequestException::class],

0 commit comments

Comments
 (0)