Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 587f6fb

Browse filesBrowse files
committed
[HttpFoundation] add more type hints
1 parent 8d76354 commit 587f6fb
Copy full SHA for 587f6fb

31 files changed

+99
-242
lines changed

‎src/Symfony/Component/HttpFoundation/AcceptHeader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/AcceptHeader.php
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function all()
125125
*/
126126
public function filter(string $pattern)
127127
{
128-
return new self(array_filter($this->items, function (AcceptHeaderItem $item) use ($pattern) {
128+
return new self(array_filter($this->items, static function (AcceptHeaderItem $item) use ($pattern) {
129129
return preg_match($pattern, $item->getValue());
130130
}));
131131
}
@@ -145,10 +145,10 @@ public function first()
145145
/**
146146
* Sorts items by descending quality.
147147
*/
148-
private function sort()
148+
private function sort(): void
149149
{
150150
if (!$this->sorted) {
151-
uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) {
151+
uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) {
152152
$qA = $a->getQuality();
153153
$qB = $b->getQuality();
154154

‎src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ public function hasAttribute(string $name)
140140
/**
141141
* Returns an attribute by its name.
142142
*
143-
* @param string $name
144-
* @param mixed $default
143+
* @param mixed $default
145144
*
146145
* @return mixed
147146
*/
@@ -163,16 +162,14 @@ public function getAttributes()
163162
/**
164163
* Set an attribute.
165164
*
166-
* @param string $value
167-
*
168165
* @return $this
169166
*/
170-
public function setAttribute(string $name, $value)
167+
public function setAttribute(string $name, string $value)
171168
{
172169
if ('q' === $name) {
173170
$this->quality = (float) $value;
174171
} else {
175-
$this->attributes[$name] = (string) $value;
172+
$this->attributes[$name] = $value;
176173
}
177174

178175
return $this;

‎src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ public static function create($file = null, int $status = 200, array $headers =
7474
/**
7575
* Sets the file to stream.
7676
*
77-
* @param \SplFileInfo|string $file The file to stream
78-
* @param string $contentDisposition
79-
* @param bool $autoEtag
80-
* @param bool $autoLastModified
77+
* @param \SplFileInfo|string $file The file to stream
8178
*
8279
* @return $this
8380
*
@@ -269,7 +266,7 @@ public function prepare(Request $request)
269266
return $this;
270267
}
271268

272-
private function hasValidIfRangeHeader(?string $header)
269+
private function hasValidIfRangeHeader(?string $header): bool
273270
{
274271
if ($this->getEtag() === $header) {
275272
return true;
@@ -317,7 +314,7 @@ public function sendContent()
317314
*
318315
* @throws \LogicException when the content is not null
319316
*/
320-
public function setContent($content)
317+
public function setContent(?string $content)
321318
{
322319
if (null !== $content) {
323320
throw new \LogicException('The content cannot be set on a BinaryFileResponse instance.');

‎src/Symfony/Component/HttpFoundation/File/File.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/File.php
+5-4Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ public function move(string $directory, string $name = null)
9696
return $target;
9797
}
9898

99-
protected function getTargetFile($directory, $name = null)
99+
/**
100+
* @return self
101+
*/
102+
protected function getTargetFile(string $directory, string $name = null)
100103
{
101104
if (!is_dir($directory)) {
102105
if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
@@ -114,9 +117,7 @@ protected function getTargetFile($directory, $name = null)
114117
/**
115118
* Returns locale independent base name of the given path.
116119
*
117-
* @param string $name The new file name
118-
*
119-
* @return string containing
120+
* @return string
120121
*/
121122
protected function getName(string $name)
122123
{

‎src/Symfony/Component/HttpFoundation/File/UploadedFile.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/UploadedFile.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public function getErrorMessage()
277277

278278
$errorCode = $this->error;
279279
$maxFilesize = UPLOAD_ERR_INI_SIZE === $errorCode ? self::getMaxFilesize() / 1024 : 0;
280-
$message = isset($errors[$errorCode]) ? $errors[$errorCode] : 'The file "%s" was not uploaded due to an unknown error.';
280+
$message = $errors[$errorCode] ?? 'The file "%s" was not uploaded due to an unknown error.';
281281

282282
return sprintf($message, $this->getClientOriginalName(), $maxFilesize);
283283
}

‎src/Symfony/Component/HttpFoundation/HeaderBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/HeaderBag.php
+4-17Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public function get(string $key, string $default = null)
124124
/**
125125
* Sets a header by name.
126126
*
127-
* @param string $key The key
128127
* @param string|string[] $values The value or an array of values
129128
* @param bool $replace Whether to replace the actual value or not (true by default)
130129
*/
@@ -175,7 +174,7 @@ public function has(string $key)
175174
*/
176175
public function contains(string $key, string $value)
177176
{
178-
return \in_array($value, $this->all((string) $key));
177+
return \in_array($value, $this->all($key));
179178
}
180179

181180
/**
@@ -197,14 +196,11 @@ public function remove(string $key)
197196
/**
198197
* Returns the HTTP header value converted to a date.
199198
*
200-
* @param string $key The parameter key
201-
* @param \DateTime $default The default value
202-
*
203-
* @return \DateTime|null The parsed DateTime or the default value if the header does not exist
199+
* @return \DateTimeInterface|null The parsed DateTime or the default value if the header does not exist
204200
*
205201
* @throws \RuntimeException When the HTTP header is not parseable
206202
*/
207-
public function getDate(string $key, \DateTime $default = null)
203+
public function getDate(string $key, \DateTimeInterface $default = null)
208204
{
209205
if (null === $value = $this->get($key)) {
210206
return $default;
@@ -220,8 +216,7 @@ public function getDate(string $key, \DateTime $default = null)
220216
/**
221217
* Adds a custom Cache-Control directive.
222218
*
223-
* @param string $key The Cache-Control directive name
224-
* @param mixed $value The Cache-Control directive value
219+
* @param mixed $value The Cache-Control directive value
225220
*/
226221
public function addCacheControlDirective(string $key, $value = true)
227222
{
@@ -233,8 +228,6 @@ public function addCacheControlDirective(string $key, $value = true)
233228
/**
234229
* Returns true if the Cache-Control directive is defined.
235230
*
236-
* @param string $key The Cache-Control directive
237-
*
238231
* @return bool true if the directive exists, false otherwise
239232
*/
240233
public function hasCacheControlDirective(string $key)
@@ -245,8 +238,6 @@ public function hasCacheControlDirective(string $key)
245238
/**
246239
* Returns a Cache-Control directive value by name.
247240
*
248-
* @param string $key The directive name
249-
*
250241
* @return mixed|null The directive value if defined, null otherwise
251242
*/
252243
public function getCacheControlDirective(string $key)
@@ -256,8 +247,6 @@ public function getCacheControlDirective(string $key)
256247

257248
/**
258249
* Removes a Cache-Control directive.
259-
*
260-
* @param string $key The Cache-Control directive
261250
*/
262251
public function removeCacheControlDirective(string $key)
263252
{
@@ -296,8 +285,6 @@ protected function getCacheControlHeader()
296285
/**
297286
* Parses a Cache-Control HTTP header.
298287
*
299-
* @param string $header The value of the Cache-Control HTTP header
300-
*
301288
* @return array An array representing the attribute values
302289
*/
303290
protected function parseCacheControl(string $header)

‎src/Symfony/Component/HttpFoundation/HeaderUtils.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/HeaderUtils.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ private function __construct()
3636
* HeaderUtils::split("da, en-gb;q=0.8", ",;")
3737
* // => ['da'], ['en-gb', 'q=0.8']]
3838
*
39-
* @param string $header HTTP header value
4039
* @param string $separators List of characters to split on, ordered by
4140
* precedence, e.g. ",", ";=", or ",;="
4241
*

‎src/Symfony/Component/HttpFoundation/IpUtils.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/IpUtils.php
+3-6Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ private function __construct()
3030
/**
3131
* Checks if an IPv4 or IPv6 address is contained in the list of given IPs or subnets.
3232
*
33-
* @param string $requestIp IP to check
34-
* @param string|array $ips List of IPs or subnets (can be a string if only a single one)
33+
* @param string|array $ips List of IPs or subnets (can be a string if only a single one)
3534
*
3635
* @return bool Whether the IP is valid
3736
*/
@@ -56,8 +55,7 @@ public static function checkIp(string $requestIp, $ips)
5655
* Compares two IPv4 addresses.
5756
* In case a subnet is given, it checks if it contains the request IP.
5857
*
59-
* @param string $requestIp IPv4 address to check
60-
* @param string $ip IPv4 address or subnet in CIDR notation
58+
* @param string $ip IPv4 address or subnet in CIDR notation
6159
*
6260
* @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet
6361
*/
@@ -102,8 +100,7 @@ public static function checkIp4(string $requestIp, string $ip)
102100
*
103101
* @see https://github.com/dsp/v6tools
104102
*
105-
* @param string $requestIp IPv6 address to check
106-
* @param string $ip IPv6 address or subnet in CIDR notation
103+
* @param string $ip IPv6 address or subnet in CIDR notation
107104
*
108105
* @return bool Whether the IP is valid
109106
*

‎src/Symfony/Component/HttpFoundation/ParameterBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/ParameterBag.php
+5-32Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class ParameterBag implements \IteratorAggregate, \Countable
2323
*/
2424
protected $parameters;
2525

26-
/**
27-
* @param array $parameters An array of parameters
28-
*/
2926
public function __construct(array $parameters = [])
3027
{
3128
$this->parameters = $parameters;
@@ -53,8 +50,6 @@ public function keys()
5350

5451
/**
5552
* Replaces the current parameters by a new set.
56-
*
57-
* @param array $parameters An array of parameters
5853
*/
5954
public function replace(array $parameters = [])
6055
{
@@ -63,8 +58,6 @@ public function replace(array $parameters = [])
6358

6459
/**
6560
* Adds parameters.
66-
*
67-
* @param array $parameters An array of parameters
6861
*/
6962
public function add(array $parameters = [])
7063
{
@@ -74,8 +67,7 @@ public function add(array $parameters = [])
7467
/**
7568
* Returns a parameter by name.
7669
*
77-
* @param string $key The key
78-
* @param mixed $default The default value if the parameter key does not exist
70+
* @param mixed $default The default value if the parameter key does not exist
7971
*
8072
* @return mixed
8173
*/
@@ -87,8 +79,7 @@ public function get(string $key, $default = null)
8779
/**
8880
* Sets a parameter by name.
8981
*
90-
* @param string $key The key
91-
* @param mixed $value The value
82+
* @param mixed $value The value
9283
*/
9384
public function set(string $key, $value)
9485
{
@@ -107,8 +98,6 @@ public function has(string $key)
10798

10899
/**
109100
* Removes a parameter.
110-
*
111-
* @param string $key The key
112101
*/
113102
public function remove(string $key)
114103
{
@@ -118,9 +107,6 @@ public function remove(string $key)
118107
/**
119108
* Returns the alphabetic characters of the parameter value.
120109
*
121-
* @param string $key The parameter key
122-
* @param string $default The default value if the parameter key does not exist
123-
*
124110
* @return string The filtered value
125111
*/
126112
public function getAlpha(string $key, string $default = '')
@@ -131,9 +117,6 @@ public function getAlpha(string $key, string $default = '')
131117
/**
132118
* Returns the alphabetic characters and digits of the parameter value.
133119
*
134-
* @param string $key The parameter key
135-
* @param string $default The default value if the parameter key does not exist
136-
*
137120
* @return string The filtered value
138121
*/
139122
public function getAlnum(string $key, string $default = '')
@@ -144,9 +127,6 @@ public function getAlnum(string $key, string $default = '')
144127
/**
145128
* Returns the digits of the parameter value.
146129
*
147-
* @param string $key The parameter key
148-
* @param string $default The default value if the parameter key does not exist
149-
*
150130
* @return string The filtered value
151131
*/
152132
public function getDigits(string $key, string $default = '')
@@ -158,9 +138,6 @@ public function getDigits(string $key, string $default = '')
158138
/**
159139
* Returns the parameter value converted to integer.
160140
*
161-
* @param string $key The parameter key
162-
* @param int $default The default value if the parameter key does not exist
163-
*
164141
* @return int The filtered value
165142
*/
166143
public function getInt(string $key, int $default = 0)
@@ -171,9 +148,6 @@ public function getInt(string $key, int $default = 0)
171148
/**
172149
* Returns the parameter value converted to boolean.
173150
*
174-
* @param string $key The parameter key
175-
* @param bool $default The default value if the parameter key does not exist
176-
*
177151
* @return bool The filtered value
178152
*/
179153
public function getBoolean(string $key, bool $default = false)
@@ -184,10 +158,9 @@ public function getBoolean(string $key, bool $default = false)
184158
/**
185159
* Filter key.
186160
*
187-
* @param string $key Key
188-
* @param mixed $default Default = null
189-
* @param int $filter FILTER_* constant
190-
* @param mixed $options Filter options
161+
* @param mixed $default Default = null
162+
* @param int $filter FILTER_* constant
163+
* @param mixed $options Filter options
191164
*
192165
* @see https://php.net/filter-var
193166
*

‎src/Symfony/Component/HttpFoundation/RedirectResponse.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/RedirectResponse.php
+1-6Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class RedirectResponse extends Response
2525
*
2626
* @param string $url The URL to redirect to. The URL should be a full URL, with schema etc.,
2727
* but practically every browser redirects on paths only as well
28-
* @param int $status The status code (302 by default)
2928
* @param array $headers The headers (Location is always set to the given URL)
3029
*
3130
* @throws \InvalidArgumentException
@@ -50,10 +49,6 @@ public function __construct(string $url, int $status = 302, array $headers = [])
5049
/**
5150
* Factory method for chainability.
5251
*
53-
* @param string $url The url to redirect to
54-
* @param int $status The response status code
55-
* @param array $headers An array of response headers
56-
*
5752
* @return static
5853
*/
5954
public static function create(string $url = '', int $status = 302, array $headers = [])
@@ -82,7 +77,7 @@ public function getTargetUrl()
8277
*/
8378
public function setTargetUrl(string $url)
8479
{
85-
if ('' === ($url ?? '')) {
80+
if ('' === $url) {
8681
throw new \InvalidArgumentException('Cannot redirect to an empty URL.');
8782
}
8883

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.