Skip to content

Commit c9e6f83

Browse files
wouterjnicolas-grekas
authored andcommitted
[Components] Convert to native return types
1 parent 63de87e commit c9e6f83

25 files changed

+104
-364
lines changed

BinaryFileResponse.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,8 @@ public function getContent(): string|false
358358

359359
/**
360360
* Trust X-Sendfile-Type header.
361-
*
362-
* @return void
363361
*/
364-
public static function trustXSendfileTypeHeader()
362+
public static function trustXSendfileTypeHeader(): void
365363
{
366364
self::$trustXSendfileTypeHeader = true;
367365
}

FileBag.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,13 @@ public function __construct(array $parameters = [])
3131
$this->replace($parameters);
3232
}
3333

34-
/**
35-
* @return void
36-
*/
37-
public function replace(array $files = [])
34+
public function replace(array $files = []): void
3835
{
3936
$this->parameters = [];
4037
$this->add($files);
4138
}
4239

43-
/**
44-
* @return void
45-
*/
46-
public function set(string $key, mixed $value)
40+
public function set(string $key, mixed $value): void
4741
{
4842
if (!\is_array($value) && !$value instanceof UploadedFile) {
4943
throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
@@ -52,10 +46,7 @@ public function set(string $key, mixed $value)
5246
parent::set($key, $this->convertFileInformation($value));
5347
}
5448

55-
/**
56-
* @return void
57-
*/
58-
public function add(array $files = [])
49+
public function add(array $files = []): void
5950
{
6051
foreach ($files as $key => $file) {
6152
$this->set($key, $file);

HeaderBag.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,17 @@ public function keys(): array
8686

8787
/**
8888
* Replaces the current HTTP headers by a new set.
89-
*
90-
* @return void
9189
*/
92-
public function replace(array $headers = [])
90+
public function replace(array $headers = []): void
9391
{
9492
$this->headers = [];
9593
$this->add($headers);
9694
}
9795

9896
/**
9997
* Adds new headers the current HTTP headers set.
100-
*
101-
* @return void
10298
*/
103-
public function add(array $headers)
99+
public function add(array $headers): void
104100
{
105101
foreach ($headers as $key => $values) {
106102
$this->set($key, $values);
@@ -130,10 +126,8 @@ public function get(string $key, string $default = null): ?string
130126
*
131127
* @param string|string[]|null $values The value or an array of values
132128
* @param bool $replace Whether to replace the actual value or not (true by default)
133-
*
134-
* @return void
135129
*/
136-
public function set(string $key, string|array|null $values, bool $replace = true)
130+
public function set(string $key, string|array|null $values, bool $replace = true): void
137131
{
138132
$key = strtr($key, self::UPPER, self::LOWER);
139133

@@ -176,10 +170,8 @@ public function contains(string $key, string $value): bool
176170

177171
/**
178172
* Removes a header.
179-
*
180-
* @return void
181173
*/
182-
public function remove(string $key)
174+
public function remove(string $key): void
183175
{
184176
$key = strtr($key, self::UPPER, self::LOWER);
185177

@@ -193,11 +185,9 @@ public function remove(string $key)
193185
/**
194186
* Returns the HTTP header value converted to a date.
195187
*
196-
* @return \DateTimeImmutable|null
197-
*
198188
* @throws \RuntimeException When the HTTP header is not parseable
199189
*/
200-
public function getDate(string $key, \DateTimeInterface $default = null): ?\DateTimeInterface
190+
public function getDate(string $key, \DateTimeInterface $default = null): ?\DateTimeImmutable
201191
{
202192
if (null === $value = $this->get($key)) {
203193
return null !== $default ? \DateTimeImmutable::createFromInterface($default) : null;
@@ -212,10 +202,8 @@ public function getDate(string $key, \DateTimeInterface $default = null): ?\Date
212202

213203
/**
214204
* Adds a custom Cache-Control directive.
215-
*
216-
* @return void
217205
*/
218-
public function addCacheControlDirective(string $key, bool|string $value = true)
206+
public function addCacheControlDirective(string $key, bool|string $value = true): void
219207
{
220208
$this->cacheControl[$key] = $value;
221209

@@ -240,10 +228,8 @@ public function getCacheControlDirective(string $key): bool|string|null
240228

241229
/**
242230
* Removes a Cache-Control directive.
243-
*
244-
* @return void
245231
*/
246-
public function removeCacheControlDirective(string $key)
232+
public function removeCacheControlDirective(string $key): void
247233
{
248234
unset($this->cacheControl[$key]);
249235

@@ -268,10 +254,7 @@ public function count(): int
268254
return \count($this->headers);
269255
}
270256

271-
/**
272-
* @return string
273-
*/
274-
protected function getCacheControlHeader()
257+
protected function getCacheControlHeader(): string
275258
{
276259
ksort($this->cacheControl);
277260

ParameterBag.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,16 @@ public function keys(): array
6060

6161
/**
6262
* Replaces the current parameters by a new set.
63-
*
64-
* @return void
6563
*/
66-
public function replace(array $parameters = [])
64+
public function replace(array $parameters = []): void
6765
{
6866
$this->parameters = $parameters;
6967
}
7068

7169
/**
7270
* Adds parameters.
73-
*
74-
* @return void
7571
*/
76-
public function add(array $parameters = [])
72+
public function add(array $parameters = []): void
7773
{
7874
$this->parameters = array_replace($this->parameters, $parameters);
7975
}
@@ -83,10 +79,7 @@ public function get(string $key, mixed $default = null): mixed
8379
return \array_key_exists($key, $this->parameters) ? $this->parameters[$key] : $default;
8480
}
8581

86-
/**
87-
* @return void
88-
*/
89-
public function set(string $key, mixed $value)
82+
public function set(string $key, mixed $value): void
9083
{
9184
$this->parameters[$key] = $value;
9285
}
@@ -101,10 +94,8 @@ public function has(string $key): bool
10194

10295
/**
10396
* Removes a parameter.
104-
*
105-
* @return void
10697
*/
107-
public function remove(string $key)
98+
public function remove(string $key): void
10899
{
109100
unset($this->parameters[$key]);
110101
}

Request.php

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,8 @@ public function __construct(array $query = [], array $request = [], array $attri
265265
* @param array $files The FILES parameters
266266
* @param array $server The SERVER parameters
267267
* @param string|resource|null $content The raw body data
268-
*
269-
* @return void
270268
*/
271-
public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null)
269+
public function initialize(array $query = [], array $request = [], array $attributes = [], array $cookies = [], array $files = [], array $server = [], $content = null): void
272270
{
273271
$this->request = new InputBag($request);
274272
$this->query = new InputBag($query);
@@ -424,10 +422,8 @@ public static function create(string $uri, string $method = 'GET', array $parame
424422
* This is mainly useful when you need to override the Request class
425423
* to keep BC with an existing system. It should not be used for any
426424
* other purpose.
427-
*
428-
* @return void
429425
*/
430-
public static function setFactory(?callable $callable)
426+
public static function setFactory(?callable $callable): void
431427
{
432428
self::$requestFactory = $callable;
433429
}
@@ -530,10 +526,8 @@ public function __toString(): string
530526
*
531527
* It overrides $_GET, $_POST, $_REQUEST, $_SERVER, $_COOKIE.
532528
* $_FILES is never overridden, see rfc1867
533-
*
534-
* @return void
535529
*/
536-
public function overrideGlobals()
530+
public function overrideGlobals(): void
537531
{
538532
$this->server->set('QUERY_STRING', static::normalizeQueryString(http_build_query($this->query->all(), '', '&')));
539533

@@ -572,10 +566,8 @@ public function overrideGlobals()
572566
*
573567
* @param array $proxies A list of trusted proxies, the string 'REMOTE_ADDR' will be replaced with $_SERVER['REMOTE_ADDR']
574568
* @param int $trustedHeaderSet A bit field of Request::HEADER_*, to set which headers to trust from your proxies
575-
*
576-
* @return void
577569
*/
578-
public static function setTrustedProxies(array $proxies, int $trustedHeaderSet)
570+
public static function setTrustedProxies(array $proxies, int $trustedHeaderSet): void
579571
{
580572
self::$trustedProxies = array_reduce($proxies, function ($proxies, $proxy) {
581573
if ('REMOTE_ADDR' !== $proxy) {
@@ -615,10 +607,8 @@ public static function getTrustedHeaderSet(): int
615607
* You should only list the hosts you manage using regexs.
616608
*
617609
* @param array $hostPatterns A list of trusted host patterns
618-
*
619-
* @return void
620610
*/
621-
public static function setTrustedHosts(array $hostPatterns)
611+
public static function setTrustedHosts(array $hostPatterns): void
622612
{
623613
self::$trustedHostPatterns = array_map(fn ($hostPattern) => sprintf('{%s}i', $hostPattern), $hostPatterns);
624614
// we need to reset trusted hosts on trusted host patterns change
@@ -663,10 +653,8 @@ public static function normalizeQueryString(?string $qs): string
663653
* If these methods are not protected against CSRF, this presents a possible vulnerability.
664654
*
665655
* The HTTP method can only be overridden when the real HTTP method is POST.
666-
*
667-
* @return void
668656
*/
669-
public static function enableHttpMethodParameterOverride()
657+
public static function enableHttpMethodParameterOverride(): void
670658
{
671659
self::$httpMethodParameterOverride = true;
672660
}
@@ -750,10 +738,7 @@ public function hasSession(bool $skipIfUninitialized = false): bool
750738
return null !== $this->session && (!$skipIfUninitialized || $this->session instanceof SessionInterface);
751739
}
752740

753-
/**
754-
* @return void
755-
*/
756-
public function setSession(SessionInterface $session)
741+
public function setSession(SessionInterface $session): void
757742
{
758743
$this->session = $session;
759744
}
@@ -1173,10 +1158,8 @@ public function getHost(): string
11731158

11741159
/**
11751160
* Sets the request method.
1176-
*
1177-
* @return void
11781161
*/
1179-
public function setMethod(string $method)
1162+
public function setMethod(string $method): void
11801163
{
11811164
$this->method = null;
11821165
$this->server->set('REQUEST_METHOD', $method);
@@ -1296,10 +1279,8 @@ public function getFormat(?string $mimeType): ?string
12961279
* Associates a format with mime types.
12971280
*
12981281
* @param string|string[] $mimeTypes The associated mime types (the preferred one must be the first as it will be used as the content type)
1299-
*
1300-
* @return void
13011282
*/
1302-
public function setFormat(?string $format, string|array $mimeTypes)
1283+
public function setFormat(?string $format, string|array $mimeTypes): void
13031284
{
13041285
if (null === static::$formats) {
13051286
static::initializeFormats();
@@ -1328,10 +1309,8 @@ public function getRequestFormat(?string $default = 'html'): ?string
13281309

13291310
/**
13301311
* Sets the request format.
1331-
*
1332-
* @return void
13331312
*/
1334-
public function setRequestFormat(?string $format)
1313+
public function setRequestFormat(?string $format): void
13351314
{
13361315
$this->format = $format;
13371316
}
@@ -1348,10 +1327,8 @@ public function getContentTypeFormat(): ?string
13481327

13491328
/**
13501329
* Sets the default locale.
1351-
*
1352-
* @return void
13531330
*/
1354-
public function setDefaultLocale(string $locale)
1331+
public function setDefaultLocale(string $locale): void
13551332
{
13561333
$this->defaultLocale = $locale;
13571334

@@ -1370,10 +1347,8 @@ public function getDefaultLocale(): string
13701347

13711348
/**
13721349
* Sets the locale.
1373-
*
1374-
* @return void
13751350
*/
1376-
public function setLocale(string $locale)
1351+
public function setLocale(string $locale): void
13771352
{
13781353
$this->setPhpDefaultLocale($this->locale = $locale);
13791354
}
@@ -1739,10 +1714,7 @@ public function preferSafeContent(): bool
17391714
* Copyright (c) 2005-2010 Zend Technologies USA Inc. (https://www.zend.com/)
17401715
*/
17411716

1742-
/**
1743-
* @return string
1744-
*/
1745-
protected function prepareRequestUri()
1717+
protected function prepareRequestUri(): string
17461718
{
17471719
$requestUri = '';
17481720

@@ -1910,10 +1882,8 @@ protected function preparePathInfo(): string
19101882

19111883
/**
19121884
* Initializes HTTP request formats.
1913-
*
1914-
* @return void
19151885
*/
1916-
protected static function initializeFormats()
1886+
protected static function initializeFormats(): void
19171887
{
19181888
static::$formats = [
19191889
'html' => ['text/html', 'application/xhtml+xml'],

RequestStack.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ class RequestStack
3131
*
3232
* This method should generally not be called directly as the stack
3333
* management should be taken care of by the application itself.
34-
*
35-
* @return void
3634
*/
37-
public function push(Request $request)
35+
public function push(Request $request): void
3836
{
3937
$this->requests[] = $request;
4038
}

Response.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,6 @@ public function prepare(Request $request): static
331331
/**
332332
* Sends HTTP headers.
333333
*
334-
* @param null|positive-int $statusCode The status code to use, override the statusCode property if set and not null
335-
*
336334
* @return $this
337335
*/
338336
public function sendHeaders(/* int $statusCode = null */): static
@@ -372,7 +370,7 @@ public function sendHeaders(/* int $statusCode = null */): static
372370
$newValues = null === $previousValues ? $values : array_diff($values, $previousValues);
373371
}
374372

375-
foreach ($newValues as $value) {
373+
foreach ($newValues as $value) {
376374
header($name.': '.$value, $replace, $this->statusCode);
377375
}
378376

0 commit comments

Comments
 (0)