Skip to content

Commit e6b52f8

Browse files
author
Thorsten Suckow-Homberg
committed
refactor: add getQuery() to Http/Request
update package sources according to PSR-12 and phpstan
1 parent 005ceee commit e6b52f8

17 files changed

+77
-15
lines changed

src/Http/Exception/BadRequestException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
*/
3838
class BadRequestException extends HttpException
3939
{
40+
/**
41+
* @var int
42+
*/
4043
protected $code = StatusCodes::HTTP_400;
4144
}

src/Http/Exception/ForbiddenException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
*/
3838
class ForbiddenException extends HttpException
3939
{
40+
/**
41+
* @var int
42+
*/
4043
protected $code = StatusCodes::HTTP_403;
4144
}

src/Http/Exception/InternalServerErrorException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
*/
3838
class InternalServerErrorException extends HttpException
3939
{
40+
/**
41+
* @var int
42+
*/
4043
protected $code = StatusCodes::HTTP_500;
4144
}

src/Http/Exception/MethodNotAllowedException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
*/
3838
class MethodNotAllowedException extends HttpException
3939
{
40+
/**
41+
* @var int
42+
*/
4043
protected $code = StatusCodes::HTTP_405;
4144
}

src/Http/Exception/NotFoundException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
*/
3838
class NotFoundException extends HttpException
3939
{
40+
/**
41+
* @var int
42+
*/
4043
protected $code = StatusCodes::HTTP_404;
4144
}

src/Http/Exception/UnauthorizedException.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@
3737
*/
3838
class UnauthorizedException extends HttpException
3939
{
40+
/**
41+
* @var int
42+
*/
4043
protected $code = StatusCodes::HTTP_401;
4144
}

src/Http/Request.php

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
namespace Conjoon\Http;
3131

32+
use Conjoon\Net\Uri\Component\Query;
3233
use Conjoon\Net\Url;
3334

3435
/**
@@ -40,13 +41,19 @@ class Request
4041
/**
4142
* @var Url
4243
*/
43-
protected readonly Url $url;
44+
private readonly Url $url;
45+
46+
47+
/**
48+
* @var Query|null
49+
*/
50+
private ?Query $query = null;
4451

4552

4653
/**
4754
* @var RequestMethod
4855
*/
49-
protected readonly RequestMethod $method;
56+
private readonly RequestMethod $method;
5057

5158

5259
/**
@@ -74,12 +81,34 @@ public function getUrl(): Url
7481

7582

7683
/**
77-
* Get the URL for the request.
84+
* Get the HTTP request method used with this request.
7885
*
7986
* @return RequestMethod
8087
*/
8188
public function getMethod(): RequestMethod
8289
{
8390
return $this->method;
8491
}
92+
93+
94+
/**
95+
* Returns the Query-component of the url of this request, or null
96+
* if no query is available.
97+
*
98+
* @return Query|null
99+
*/
100+
public function getQuery(): ?Query
101+
{
102+
if ($this->query) {
103+
return $this->query;
104+
}
105+
106+
$query = $this->url->getQuery();
107+
if (!$query) {
108+
return null;
109+
}
110+
111+
$this->query = new Query($query);
112+
return $this->query;
113+
}
85114
}

src/Http/StatusCodes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class StatusCodes
6666
public const HTTP_500 = 500;
6767

6868
/**
69-
* @var array
69+
* @var array<int, string>
7070
*/
7171
public const HTTP_STATUS = [
7272
400 => "Bad Request",

tests/Http/Exception/BadRequestExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class BadRequestExceptionTest extends TestCase
4343
/**
4444
* test instance
4545
*/
46-
public function testInstance()
46+
public function testInstance(): void
4747
{
4848

4949
$exception = new BadRequestException();

tests/Http/Exception/ForbiddenExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ForbiddenExceptionTest extends TestCase
4343
/**
4444
* test instance
4545
*/
46-
public function testInstance()
46+
public function testInstance(): void
4747
{
4848

4949
$exception = new ForbiddenException();

0 commit comments

Comments
 (0)