Skip to content

Commit fe779a4

Browse files
authoredSep 9, 2024··
Merge pull request #12 from CorpusPHP/TooManyRequestsException
Add TooManyRequestsException
2 parents 9d17bc6 + 4fcfacd commit fe779a4

File tree

6 files changed

+75
-8
lines changed

6 files changed

+75
-8
lines changed
 

‎.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
operating-system: [ubuntu-latest]
14-
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
14+
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
1515

1616
runs-on: ${{ matrix.operating-system }}
1717

‎README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ HTTP Status Codes and Exceptions
99

1010
## Requirements
1111

12-
- **php**: ^7.2 | ^8.0
12+
- **php**: ^7.3 | ^8.0
1313

1414
## Installing
1515

@@ -67,6 +67,14 @@ function getHttpStatusCode() : int
6767
function getHttpStatusCode() : int
6868
```
6969

70+
### Class: Corpus\Http\Exceptions\ClientError\TooManyRequestsException
71+
72+
#### Method: TooManyRequestsException->getHttpStatusCode
73+
74+
```php
75+
function getHttpStatusCode() : int
76+
```
77+
7078
### Class: Corpus\Http\Exceptions\ClientError\UnauthorizedException
7179

7280
#### Method: UnauthorizedException->getHttpStatusCode

‎composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.2 | ^8.0"
13+
"php": "^7.3 | ^8.0"
1414
},
1515
"autoload": {
1616
"psr-4": {
1717
"Corpus\\Http\\": "src/"
1818
}
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "~7.5 | ~9.0",
22-
"squizlabs/php_codesniffer": "^3.5",
2321
"corpus/coding-standard": "^0.6.0",
24-
"friendsofphp/php-cs-fixer": "^2.17",
25-
"phpstan/phpstan": "^1.12"
22+
"friendsofphp/php-cs-fixer": "^3.4",
23+
"phpstan/phpstan": "^1.12",
24+
"phpunit/phpunit": "^9.6",
25+
"squizlabs/php_codesniffer": "^3.5"
2626
},
2727
"config": {
2828
"allow-plugins": {

‎phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ parameters:
22
level: 9
33
paths:
44
- src
5-
phpVersion: 70200
5+
phpVersion: 70300
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Corpus\Http\Exceptions\ClientError;
4+
5+
use Corpus\Http\Status;
6+
7+
class TooManyRequestsException extends AbstractClientErrorException {
8+
9+
/** @inheritdoc */
10+
public function getHttpStatusCode() : int {
11+
return Status::TooManyRequests;
12+
}
13+
14+
}

‎test/ExceptionNamingTest.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
4+
use Corpus\Http\Exceptions\AbstractHttpException;
5+
use Corpus\Http\Status;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class ExceptionNamingTest extends TestCase {
9+
10+
public function testNaming() : void {
11+
$dir = new \RecursiveDirectoryIterator(__DIR__ . '/../src/Exceptions');
12+
$ite = new \RecursiveIteratorIterator($dir);
13+
$files = new \RegexIterator($ite, "/Exception\\.php$/");
14+
foreach( $files as $file ) {
15+
require_once $file;
16+
}
17+
18+
$classes = array_filter(get_declared_classes(), function ($class) {
19+
return is_subclass_of($class, AbstractHttpException::class);
20+
});
21+
22+
foreach($classes as $className) {
23+
$reflect = new \ReflectionClass($className);
24+
if($reflect->isAbstract()) {
25+
continue;
26+
}
27+
28+
$inst = $this->getMockBuilder($className)
29+
->onlyMethods([])
30+
->disableOriginalConstructor()
31+
->getMock();
32+
33+
assert($inst instanceof AbstractHttpException);
34+
35+
$shortName = $reflect->getShortName();
36+
$constName = preg_replace('/Exception$/', '', $shortName);
37+
38+
$this->assertSame(
39+
constant(Status::class . '::' . $constName),
40+
$inst->getHttpStatusCode()
41+
);
42+
}
43+
}
44+
45+
}

0 commit comments

Comments
 (0)
Please sign in to comment.