Skip to content

Commit 49f3f7a

Browse files
authored
Merge pull request #115 from samsonasik/apply-php74
Apply PHP 7.4 syntax and typed property
2 parents de9cd9c + 584a620 commit 49f3f7a

23 files changed

+80
-124
lines changed

psalm-baseline.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@
375375
<code>$https</code>
376376
</MissingClosureParamType>
377377
<MissingClosureReturnType occurrences="2">
378-
<code>function ($host) {</code>
379-
<code>function (string $name, array $headers, $default = null) {</code>
378+
<code>static function ($host) {</code>
379+
<code>static function (string $name, array $headers, $default = null) {</code>
380380
</MissingClosureReturnType>
381381
<MixedArgument occurrences="8">
382382
<code>$getHeaderFromArray('x-forwarded-proto', $headers, '')</code>
@@ -493,7 +493,7 @@
493493
</file>
494494
<file src="test/Request/SerializerTest.php">
495495
<MissingClosureReturnType occurrences="1">
496-
<code>function () use ($payload) {</code>
496+
<code>static function () use ($payload) {</code>
497497
</MissingClosureReturnType>
498498
<MixedArrayOffset occurrences="1">
499499
<code>$payload[$i++]</code>

src/MessageTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ private function filterHeaderValue($values): array
392392
);
393393
}
394394

395-
return array_map(function ($value) {
395+
return array_map(static function ($value): string {
396396
HeaderSecurity::assertValid($value);
397397

398398
$value = (string) $value;

src/PhpInputStream.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
*/
1212
class PhpInputStream extends Stream
1313
{
14-
/** @var string */
15-
private $cache = '';
14+
private string $cache = '';
1615

17-
/** @var bool */
18-
private $reachedEof = false;
16+
private bool $reachedEof = false;
1917

2018
/**
2119
* @param string|resource $stream

src/RelativeStream.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
*/
1717
final class RelativeStream implements StreamInterface
1818
{
19-
/** @var StreamInterface */
20-
private $decoratedStream;
19+
private StreamInterface $decoratedStream;
2120

22-
/** @var int */
23-
private $offset;
21+
private int $offset;
2422

2523
public function __construct(StreamInterface $decoratedStream, ?int $offset)
2624
{

src/Response.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ class Response implements ResponseInterface
3333
/**
3434
* Map of standard HTTP status code/reason phrases
3535
*
36-
* @var array
3736
* @psalm-var array<positive-int, non-empty-string>
3837
*/
39-
private $phrases = [
38+
private array $phrases = [
4039
// INFORMATIONAL CODES
4140
100 => 'Continue',
4241
101 => 'Switching Protocols',
@@ -110,11 +109,9 @@ class Response implements ResponseInterface
110109
599 => 'Network Connect Timeout Error',
111110
];
112111

113-
/** @var string */
114-
private $reasonPhrase;
112+
private string $reasonPhrase;
115113

116-
/** @var int */
117-
private $statusCode;
114+
private int $statusCode;
118115

119116
/**
120117
* @param string|resource|StreamInterface $body Stream identifier and/or actual stream resource

src/Response/InjectContentTypeTrait.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ trait InjectContentTypeTrait
1717
*/
1818
private function injectContentType(string $contentType, array $headers): array
1919
{
20-
$hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
21-
return $carry ?: strtolower($item) === 'content-type';
22-
}, false);
20+
$hasContentType = array_reduce(
21+
array_keys($headers),
22+
static fn($carry, $item) => $carry ?: strtolower($item) === 'content-type',
23+
false
24+
);
2325

2426
if (! $hasContentType) {
2527
$headers['content-type'] = [$contentType];

src/Response/JsonResponse.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class JsonResponse extends Response
4747
/** @var mixed */
4848
private $payload;
4949

50-
/** @var int */
51-
private $encodingOptions;
50+
private int $encodingOptions;
5251

5352
/**
5453
* Create a JSON response with the given data.

src/ServerRequest.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,18 @@ class ServerRequest implements ServerRequestInterface
3333
{
3434
use RequestTrait;
3535

36-
/** @var array */
37-
private $attributes = [];
36+
private array $attributes = [];
3837

39-
/** @var array */
40-
private $cookieParams = [];
38+
private array $cookieParams = [];
4139

4240
/** @var null|array|object */
4341
private $parsedBody;
4442

45-
/** @var array */
46-
private $queryParams = [];
43+
private array $queryParams = [];
4744

48-
/** @var array */
49-
private $serverParams;
45+
private array $serverParams;
5046

51-
/** @var array */
52-
private $uploadedFiles;
47+
private array $uploadedFiles;
5348

5449
/**
5550
* @param array $serverParams Server parameters, typically from $_SERVER

src/ServerRequestFilter/FilterUsingXForwardedHeaders.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ final class FilterUsingXForwardedHeaders implements FilterServerRequestInterface
4242
];
4343

4444
/** @var list<FilterUsingXForwardedHeaders::HEADER_*> */
45-
private $trustedHeaders;
45+
private array $trustedHeaders;
4646

4747
/** @var list<non-empty-string> */
48-
private $trustedProxies;
48+
private array $trustedProxies;
4949

5050
/**
5151
* Only allow construction via named constructors

src/UploadedFile.php

+6-12
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,17 @@ class UploadedFile implements UploadedFileInterface
4444
UPLOAD_ERR_EXTENSION => 'A PHP extension stopped the file upload.',
4545
];
4646

47-
/** @var string|null */
48-
private $clientFilename;
47+
private ?string $clientFilename;
4948

50-
/** @var string|null */
51-
private $clientMediaType;
49+
private ?string $clientMediaType;
5250

53-
/** @var int */
54-
private $error;
51+
private int $error;
5552

56-
/** @var null|string */
57-
private $file;
53+
private ?string $file = null;
5854

59-
/** @var bool */
60-
private $moved = false;
55+
private bool $moved = false;
6156

62-
/** @var int */
63-
private $size;
57+
private int $size;
6458

6559
/** @var null|StreamInterface */
6660
private $stream;

src/Uri.php

+7-15
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,25 @@ class Uri implements UriInterface
5959
'https' => 443,
6060
];
6161

62-
/** @var string */
63-
private $scheme = '';
62+
private string $scheme = '';
6463

65-
/** @var string */
66-
private $userInfo = '';
64+
private string $userInfo = '';
6765

68-
/** @var string */
69-
private $host = '';
66+
private string $host = '';
7067

7168
/** @var int|null */
7269
private $port;
7370

74-
/** @var string */
75-
private $path = '';
71+
private string $path = '';
7672

77-
/** @var string */
78-
private $query = '';
73+
private string $query = '';
7974

80-
/** @var string */
81-
private $fragment = '';
75+
private string $fragment = '';
8276

8377
/**
8478
* generated uri string cache
85-
*
86-
* @var string|null
8779
*/
88-
private $uriString;
80+
private ?string $uriString = null;
8981

9082
public function __construct(string $uri = '')
9183
{

src/functions/marshal_headers_from_sapi.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ function marshalHeadersFromSapi(array $server): array
2626
];
2727
return isset($contentHeaders[$key]);
2828
}
29-
: static function (string $key): bool {
30-
return strpos($key, 'CONTENT_') === 0;
31-
};
29+
: static fn(string $key): bool => strpos($key, 'CONTENT_') === 0;
3230

3331
$headers = [];
3432
foreach ($server as $key => $value) {

src/functions/marshal_uri_from_sapi.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function marshalUriFromSapi(array $server, array $headers): Uri
4242
* @param mixed $default Default value to return if header not found
4343
* @return mixed
4444
*/
45-
$getHeaderFromArray = function (string $name, array $headers, $default = null) {
45+
$getHeaderFromArray = static function (string $name, array $headers, $default = null) {
4646
$header = strtolower($name);
4747
$headers = array_change_key_case($headers, CASE_LOWER);
4848
if (array_key_exists($header, $headers)) {
@@ -58,13 +58,13 @@ function marshalUriFromSapi(array $server, array $headers): Uri
5858
* @return array Array of two items, host and port, in that order (can be
5959
* passed to a list() operation).
6060
*/
61-
$marshalHostAndPort = function (array $headers, array $server) use ($getHeaderFromArray): array {
61+
$marshalHostAndPort = static function (array $headers, array $server) use ($getHeaderFromArray): array {
6262
/**
63-
* @param string|array $host
64-
* @return array Array of two items, host and port, in that order (can be
65-
* passed to a list() operation).
66-
*/
67-
$marshalHostAndPortFromHeader = function ($host) {
63+
* @param string|array $host
64+
* @return array Array of two items, host and port, in that order (can be
65+
* passed to a list() operation).
66+
*/
67+
$marshalHostAndPortFromHeader = static function ($host) {
6868
if (is_array($host)) {
6969
$host = implode(', ', $host);
7070
}
@@ -81,10 +81,10 @@ function marshalUriFromSapi(array $server, array $headers): Uri
8181
};
8282

8383
/**
84-
* @return array Array of two items, host and port, in that order (can be
85-
* passed to a list() operation).
86-
*/
87-
$marshalIpv6HostAndPort = function (array $server, ?int $port): array {
84+
* @return array Array of two items, host and port, in that order (can be
85+
* passed to a list() operation).
86+
*/
87+
$marshalIpv6HostAndPort = static function (array $server, ?int $port): array {
8888
$host = '[' . $server['SERVER_ADDR'] . ']';
8989
$port = $port ?: 80;
9090
if ($port . ']' === substr($host, strrpos($host, ':') + 1)) {
@@ -138,7 +138,7 @@ function marshalUriFromSapi(array $server, array $headers): Uri
138138
*
139139
* From Laminas\Http\PhpEnvironment\Request class
140140
*/
141-
$marshalRequestPath = function (array $server): string {
141+
$marshalRequestPath = static function (array $server): string {
142142
// IIS7 with URL Rewrite: make sure we get the unencoded url
143143
// (double slash problem).
144144
$iisUrlRewritten = $server['IIS_WasUrlRewritten'] ?? null;
@@ -165,7 +165,7 @@ function marshalUriFromSapi(array $server, array $headers): Uri
165165

166166
// URI scheme
167167
$scheme = 'http';
168-
$marshalHttpsValue = function ($https): bool {
168+
$marshalHttpsValue = static function ($https): bool {
169169
if (is_bool($https)) {
170170
return $https;
171171
}

src/functions/normalize_uploaded_files.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function normalizeUploadedFiles(array $files): array
3030
* @param string[]|array[]|null $typeTree
3131
* @return UploadedFile[]|array[]
3232
*/
33-
$recursiveNormalize = function (
33+
$recursiveNormalize = static function (
3434
array $tmpNameTree,
3535
array $sizeTree,
3636
array $errorTree,
@@ -75,7 +75,7 @@ function normalizeUploadedFiles(array $files): array
7575
* @param array $files
7676
* @return UploadedFile[]
7777
*/
78-
$normalizeUploadedFileSpecification = function (array $files = []) use (&$recursiveNormalize): array {
78+
$normalizeUploadedFileSpecification = static function (array $files = []) use (&$recursiveNormalize): array {
7979
if (
8080
! isset($files['tmp_name']) || ! is_array($files['tmp_name'])
8181
|| ! isset($files['size']) || ! is_array($files['size'])

0 commit comments

Comments
 (0)