8000 [HttpFoundation] add more type hints · symfony/symfony@e2820cc · GitHub
[go: up one dir, main page]

Skip to content

Commit e2820cc

Browse files
committed
[HttpFoundation] add more type hints
1 parent dbe0e37 commit e2820cc

30 files changed

+89
-254
lines changed

src/Symfony/Component/HttpFoundation/AcceptHeader.php

Lines 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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ public function hasAttribute(string $name)
140140
/**
141141
* Returns an attribute by its name.
142142
*
143-
* @param string $name
144-
* @param mixed $default
145-
*
146143
* @return mixed
147144
*/
148145
public function getAttribute(string $name, $default = null)
@@ -163,16 +160,14 @@ public function getAttributes()
163160
/**
164161
* Set an attribute.
165162
*
166-
* @param string $value
167-
*
168163
* @return $this
169164
*/
170-
public function setAttribute(string $name, $value)
165+
public function setAttribute(string $name, string $value)
171166
{
172167
if ('q' === $name) {
173168
$this->quality = (float) $value;
174169
} else {
175-
$this->attributes[$name] = (string) $value;
170+
$this->attributes[$name] = $value;
176171
}
177172

178173
return $this;

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines 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

Lines 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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,6 @@ public function isValid()
164164
/**
165165
* Moves the file to a new location.
166166
*
167-
* @param string $directory The destination folder
168-
* @param string|null $name The new file name
169-
*
< E377 /td>
170167
* @return File A File object representing the new file
171168
*
172169
* @throws FileException if, for any reason, the file could not have been moved

src/Symfony/Component/HttpFoundation/HeaderBag.php

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class HeaderBag implements \IteratorAggregate, \Countable
2121
protected $headers = [];
2222
protected $cacheControl = [];
2323

24-
/**
25-
* @param array $headers An array of HTTP headers
26-
*/
2724
public function __construct(array $headers = [])
2825
{
2926
foreach ($headers as $key => $values) {
@@ -85,8 +82,6 @@ public function keys()
8582

8683
/**
8784
* Replaces the current HTTP headers by a new set.
88-
*
89-
* @param array $headers An array of HTTP headers
9085
*/
9186
public function replace(array $headers = [])
9287
{
@@ -96,8 +91,6 @@ public function replace(array $headers = [])
9691

9792
/**
9893
* Adds new headers the current HTTP headers set.
99-
*
100-
* @param array $headers An array of HTTP headers
10194
*/
10295
public function add(array $headers)
10396
{
@@ -109,9 +102,6 @@ public function add(array $headers)
109102
/**
110103
* Returns a header value by name.
111104
*
112-
* @param string $key The header name
113-
* @param string|null $default The default value
114-
*
115105
* @return string|null The first header value or default value
116106
*/
117107
public function get(string $key, string $default = null)
@@ -124,7 +114,6 @@ public function get(string $key, string $default = null)
124114
/**
125115
* Sets a header by name.
126116
*
127-
* @param string $key The key
128117
* @param string|string[] $values The value or an array of values
129118
* @param bool $replace Whether to replace the actual value or not (true by default)
130119
*/
@@ -156,8 +145,6 @@ public function set(string $key, $values, bool $replace = true)
156145
/**
157146
* Returns true if the HTTP header is defined.
158147
*
159-
* @param string $key The HTTP header
160-
*
161148
* @return bool true if the parameter exists, false otherwise
162149
*/
163150
public function has(string $key)
@@ -168,20 +155,15 @@ public function has(string $key)
168155
/**
169156
* Returns true if the given HTTP header contains the given value.
170157
*
171-
* @param string $key The HTTP header name
172-
* @param string $value The HTTP value
173-
*
174158
* @return bool true if the value is contained in the header, false otherwise
175159
*/
176160
public function contains(string $key, string $value)
177161
{
178-
return \in_array($value, $this->all((string) $key));
162+
return \in_array($value, $this->all($key));
179163
}
180164

181165
/**
182166
* Removes a header.
183-
*
184-
* @param string $key The HTTP header name
185167
*/
186168
public function remove(string $key)
187169
{
@@ -197,10 +179,7 @@ public function remove(string $key)
197179
/**
198180
* Returns the HTTP header value converted to a date.
199181
*
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
182+
* @return \DateTimeInterface|null The parsed DateTime or the default value if the header does not exist
204183
*
205184
* @throws \RuntimeException When the HTTP header is not parseable
206185
*/
@@ -220,8 +199,7 @@ public function getDate(string $key, \DateTime $default = null)
220199
/**
221200
* Adds a custom Cache-Control directive.
222201
*
223-
* @param string $key The Cache-Control directive name
224-
* @param mixed $value The Cache-Control directive value
202+
* @param mixed $value The Cache-Control directive value
225203
*/
226204
public function addCacheControlDirective(string $key, $value = true)
227205
{
@@ -233,8 +211,6 @@ public function addCacheControlDirective(string $key, $value = true)
233211
/**
234212
* Returns true if the Cache-Control directive is defined.
235213
*
236-
* @param string $key The Cache-Control directive
237-
*
238214
* @return bool true if the directive exists, false otherwise
239215
*/
240216
public function hasCacheControlDirective(string $key)
@@ -245,8 +221,6 @@ public function hasCacheControlDirective(string $key)
245221
/**
246222
* Returns a Cache-Control directive value by name.
247223
*
248-
* @param string $key The directive name
249-
*
250224
* @return mixed|null The directive value if defined, null otherwise
251225
*/
252226
public function getCacheControlDirective(string $key)
@@ -256,8 +230,6 @@ public function getCacheControlDirective(string $key)
256230

257231
/**
258232
* Removes a Cache-Control directive.
259-
*
260-
* @param string $key The Cache-Control directive
261233
*/
262234
public function removeCacheControlDirective(string $key)
263235
{
@@ -296,8 +268,6 @@ protected function getCacheControlHeader()
296268
/**
297269
* Parses a Cache-Control HTTP header.
298270
*
299-
* @param string $header The value of the Cache-Control HTTP header
300-
*
301271
* @return array An array representing the attribute values
302272
*/
303273
protected function parseCacheControl(string $header)

src/Symfony/Component/HttpFoundation/HeaderUtils.php

Lines 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

Lines 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
*

0 commit comments

Comments
 (0)
0