Skip to content

Commit 778a418

Browse files
committed
Added property & return type hints
1 parent 6426b21 commit 778a418

14 files changed

+328
-327
lines changed

src/Cookie/CookieSetup.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class CookieSetup
2020
{
2121
private const FIVE_YEARS_IN_SEC = 157680000;
2222

23-
private $responseHeaders;
24-
private $directives;
23+
private ResponseHeaders $responseHeaders;
24+
private array $directives;
2525

2626
/**
2727
* @param ResponseHeaders $responseHeaders
@@ -96,7 +96,7 @@ public function cookie(string $name): Cookie
9696
*
9797
* @return Cookie
9898
*/
99-
public function permanentCookie($name): Cookie
99+
public function permanentCookie(string $name): Cookie
100100
{
101101
$this->maxAge(self::FIVE_YEARS_IN_SEC);
102102
return $this->cookie($name);
@@ -111,7 +111,7 @@ public function permanentCookie($name): Cookie
111111
*
112112
* @return Cookie
113113
*/
114-
public function sessionCookie($name): Cookie
114+
public function sessionCookie(string $name): Cookie
115115
{
116116
$this->httpOnly();
117117
$this->sameSite('Lax');

src/Cookie/HeadersContextCookie.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ class HeadersContextCookie implements Cookie
2121
{
2222
const DIRECTIVE_NAMES = ['Domain', 'Path', 'Expires', 'MaxAge', 'Secure', 'HttpOnly', 'SameSite'];
2323

24-
private $name;
25-
private $directives;
26-
private $headers;
24+
private string $name;
25+
private array $directives;
26+
private ResponseHeaders $headers;
2727

28-
private $sent = false;
28+
private bool $sent = false;
2929

3030
/**
3131
* @param string $name

src/Header/SetCookieHeader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717

1818
class SetCookieHeader implements Header
1919
{
20-
private $header;
20+
private string $headerValue;
2121

2222
/**
23-
* @param string $header
23+
* @param string $headerValue
2424
*/
25-
public function __construct(string $header)
25+
public function __construct(string $headerValue)
2626
{
27-
$this->header = $header;
27+
$this->headerValue = $headerValue;
2828
}
2929

3030
public function addToMessage(MessageInterface $message): MessageInterface
3131
{
32-
return $message->withAddedHeader('Set-Cookie', $this->header);
32+
return $message->withAddedHeader('Set-Cookie', $this->headerValue);
3333
}
3434
}

src/ResponseHeaders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
final class ResponseHeaders implements MiddlewareInterface
2222
{
23-
private $headers = [];
23+
private array $headers;
2424

2525
/**
2626
* @param Header[] $headers

tests/Doubles/DummyServerRequest.php

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of Polymorphine/Headers package.
5+
*
6+
* (c) Shudd3r <q3.shudder@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Polymorphine\Headers\Tests\Doubles;
13+
14+
use Psr\Http\Message\ServerRequestInterface;
15+
use Psr\Http\Message\StreamInterface;
16+
use Psr\Http\Message\UriInterface;
17+
18+
19+
class DummyServerRequest implements ServerRequestInterface
20+
{
21+
public ?UriInterface $uri;
22+
23+
public function __construct(UriInterface $uri = null)
24+
{
25+
$this->uri = $uri;
26+
}
27+
28+
public function getMethod(): string
29+
{
30+
return 'GET';
31+
}
32+
33+
public function getUri(): UriInterface
34+
{
35+
return $this->uri;
36+
}
37+
38+
public function getRequestTarget(): string
39+
{
40+
return 'foo?bar=baz';
41+
}
42+
43+
public function getProtocolVersion(): string
44+
{
45+
return '1.1';
46+
}
47+
48+
public function withProtocolVersion($version): self
49+
{
50+
return $this;
51+
}
52+
53+
public function getHeaders(): array
54+
{
55+
return [];
56+
}
57+
58+
public function hasHeader($name): bool
59+
{
60+
return false;
61+
}
62+
63+
public function getHeader($name): array
64+
{
65+
return [];
66+
}
67+
68+
public function getHeaderLine($name): string
69+
{
70+
return '';
71+
}
72+
73+
public function withHeader($name, $value): self
74+
{
75+
return $this;
76+
}
77+
78+
public function withAddedHeader($name, $value): self
79+
{
80+
return $this;
81+
}
82+
83+
public function withoutHeader($name): self
84+
{
85+
return $this;
86+
}
87+
88+
public function getBody(): StreamInterface
89+
{
90+
return new DummyStream();
91+
}
92+
93+
public function withBody(StreamInterface $body): self
94+
{
95+
return $this;
96+
}
97+
98+
public function withRequestTarget($requestTarget): self
99+
{
100+
return $this;
101+
}
102+
103+
public function withMethod($method): self
104+
{
105+
return $this;
106+
}
107+
108+
public function withUri(UriInterface $uri, $preserveHost = false): self
109+
{
110+
return $this;
111+
}
112+
113+
public function getServerParams(): array
114+
{
115+
return [];
116+
}
117+
118+
public function getCookieParams(): array
119+
{
120+
return [];
121+
}
122+
123+
public function withCookieParams(array $cookies): self
124+
{
125+
return $this;
126+
}
127+
128+
public function getQueryParams(): array
129+
{
130+
return [];
131+
}
132+
133+
public function withQueryParams(array $query): self
134+
{
135+
return $this;
136+
}
137+
138+
public function getUploadedFiles(): array
139+
{
140+
return [];
141+
}
142+
143+
public function withUploadedFiles(array $uploadedFiles): self
144+
{
145+
return $this;
146+
}
147+
148+
public function getParsedBody(): array
149+
{
150+
return [];
151+
}
152+
153+
public function withParsedBody($data): self
154+
{
155+
return $this;
156+
}
157+
158+
public function getAttributes(): array
159+
{
160+
return [];
161+
}
162+
163+
public function getAttribute($name, $default = null)
164+
{
165+
return $default;
166+
}
167+
168+
public function withAttribute($name, $value): self
169+
{
170+
return $this;
171+
}
172+
173+
public function withoutAttribute($name): self
174+
{
175+
return $this;
176+
}
177+
}

tests/Doubles/DummyStream.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of Polymorphine/Headers package.
5+
*
6+
* (c) Shudd3r <q3.shudder@gmail.com>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Polymorphine\Headers\Tests\Doubles;
13+
14+
use Psr\Http\Message\StreamInterface;
15+
16+
17+
class DummyStream implements StreamInterface
18+
{
19+
public function __toString(): string
20+
{
21+
return 'Hello world';
22+
}
23+
24+
public function close(): void
25+
{
26+
}
27+
28+
public function detach()
29+
{
30+
}
31+
32+
public function getSize(): ?int
33+
{
34+
return 10;
35+
}
36+
37+
public function tell(): int
38+
{
39+
return 5;
40+
}
41+
42+
public function eof(): bool
43+
{
44+
return false;
45+
}
46+
47+
public function isSeekable(): bool
48+
{
49+
return true;
50+
}
51+
52+
public function seek($offset, $whence = SEEK_SET): void
53+
{
54+
}
55+
56+
public function rewind(): void
57+
{
58+
}
59+
60+
public function isWritable(): bool
61+
{
62+
return true;
63+
}
64+
65+
public function write($string): void
66+
{
67+
}
68+
69+
public function isReadable(): bool
70+
{
71+
return true;
72+
}
73+
74+
public function read($length): string
75+
{
76+
return 'Hello';
77+
}
78+
79+
public function getContents(): string
80+
{
81+
return ' World';
82+
}
83+
84+
public function getMetadata($key = null): array
85+
{
86+
return [];
87+
}
88+
}

tests/Doubles/FakeHeader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
class FakeHeader implements Header
1919
{
20-
private $name;
21-
private $value;
20+
private string $name;
21+
private string $value;
2222

2323
public function __construct(string $name, string $value)
2424
{

tests/Doubles/FakeRequestHandler.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@
1818

1919
class FakeRequestHandler implements RequestHandlerInterface
2020
{
21-
private $response;
22-
private $sideEffect;
21+
private ResponseInterface $response;
2322

24-
public function __construct(ResponseInterface $response, callable $sideEffect = null)
23+
public function __construct(ResponseInterface $response)
2524
{
26-
$this->response = $response;
27-
$this->sideEffect = $sideEffect;
25+
$this->response = $response;
2826
}
2927

3028
public function handle(ServerRequestInterface $request): ResponseInterface
3129
{
32-
if ($this->sideEffect) { ($this->sideEffect)(); }
3330
return $this->response;
3431
}
3532
}

0 commit comments

Comments
 (0)