Skip to content

Commit ed43209

Browse files
committed
Updated codebase to new standards and php 7.4
2 parents 749451a + 778a418 commit ed43209

19 files changed

+374
-342
lines changed

cs-fixer.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Headers package.

src/Cookie.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ interface Cookie
2020
const NAME_EXTRA_CHARS = '!\#$%&\'*+\-.^_`|~';
2121
const VALUE_EXTRA_CHARS = self::NAME_EXTRA_CHARS . '\/:=?\@()[\]{}<>';
2222

23+
/**
24+
* @return string
25+
*/
2326
public function name(): string;
2427

2528
/**

src/Cookie/CookieSetup.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Headers package.
@@ -20,9 +20,12 @@ 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

26+
/**
27+
* @param ResponseHeaders $responseHeaders
28+
*/
2629
public function __construct(ResponseHeaders $responseHeaders)
2730
{
2831
$this->responseHeaders = $responseHeaders;
@@ -54,7 +57,7 @@ public function directives(array $directives = []): self
5457
'MaxAge' => null,
5558
'Secure' => false,
5659
'HttpOnly' => false,
57-
'SameSite' => false
60+
'SameSite' => null
5861
];
5962

6063
foreach (HeadersContextCookie::DIRECTIVE_NAMES as $name) {
@@ -93,7 +96,7 @@ public function cookie(string $name): Cookie
9396
*
9497
* @return Cookie
9598
*/
96-
public function permanentCookie($name): Cookie
99+
public function permanentCookie(string $name): Cookie
97100
{
98101
$this->maxAge(self::FIVE_YEARS_IN_SEC);
99102
return $this->cookie($name);
@@ -108,7 +111,7 @@ public function permanentCookie($name): Cookie
108111
*
109112
* @return Cookie
110113
*/
111-
public function sessionCookie($name): Cookie
114+
public function sessionCookie(string $name): Cookie
112115
{
113116
$this->httpOnly();
114117
$this->sameSite('Lax');

src/Cookie/Exception/CookieAlreadySentException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Headers package.

src/Cookie/Exception/IllegalCharactersException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Headers package.

src/Cookie/HeadersContextCookie.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Headers package.
@@ -21,12 +21,17 @@ 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

30+
/**
31+
* @param string $name
32+
* @param array $directives
33+
* @param ResponseHeaders $headers
34+
*/
3035
public function __construct(string $name, array $directives, ResponseHeaders $headers)
3136
{
3237
$this->name = $this->validName($name);

src/Header.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@
1616

1717
interface Header
1818
{
19+
/**
20+
* @param MessageInterface $message
21+
*
22+
* @return MessageInterface New Message instance with modified headers
23+
*/
1924
public function addToMessage(MessageInterface $message): MessageInterface;
2025
}

src/Header/SetCookieHeader.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Headers package.
@@ -17,15 +17,18 @@
1717

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

22-
public function __construct(string $header)
22+
/**
23+
* @param string $headerValue
24+
*/
25+
public function __construct(string $headerValue)
2326
{
24-
$this->header = $header;
27+
$this->headerValue = $headerValue;
2528
}
2629

2730
public function addToMessage(MessageInterface $message): MessageInterface
2831
{
29-
return $message->withAddedHeader('Set-Cookie', $this->header);
32+
return $message->withAddedHeader('Set-Cookie', $this->headerValue);
3033
}
3134
}

src/ResponseHeaders.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
/*
44
* This file is part of Polymorphine/Headers package.
@@ -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
@@ -39,11 +39,22 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
3939
return $response;
4040
}
4141

42+
/**
43+
* Adds Header that will modify server Response.
44+
*
45+
* @param Header $header
46+
*/
4247
public function push(Header $header): void
4348
{
4449
$this->headers[] = $header;
4550
}
4651

52+
/**
53+
* CookieSetup object can be used to configure Cookie header
54+
* in server Response.
55+
*
56+
* @return CookieSetup
57+
*/
4758
public function cookieSetup(): CookieSetup
4859
{
4960
return new CookieSetup($this);

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+
}

0 commit comments

Comments
 (0)