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 b1be9ce

Browse filesBrowse files
julien57nicolas-grekas
julien57
authored andcommitted
add type-hints
1 parent 7f10099 commit b1be9ce
Copy full SHA for b1be9ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner

47 files changed

+251
-527
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/AcceptHeader.php
+6-14Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ public function __construct(array $items)
4444
/**
4545
* Builds an AcceptHeader instance from a string.
4646
*
47-
* @param string $headerValue
48-
*
4947
* @return self
5048
*/
51-
public static function fromString($headerValue)
49+
public static function fromString(?string $headerValue)
5250
{
5351
$index = 0;
5452

55-
$parts = HeaderUtils::split((string) $headerValue, ',;=');
53+
$parts = HeaderUtils::split($headerValue ?? '', ',;=');
5654

5755
return new self(array_map(function ($subParts) use (&$index) {
5856
$part = array_shift($subParts);
@@ -78,23 +76,19 @@ public function __toString()
7876
/**
7977
* Tests if header has given value.
8078
*
81-
* @param string $value
82-
*
8379
* @return bool
8480
*/
85-
public function has($value)
81+
public function has(string $value)
8682
{
8783
return isset($this->items[$value]);
8884
}
8985

9086
/**
9187
* Returns given value's item, if exists.
9288
*
93-
* @param string $value
94-
*
9589
* @return AcceptHeaderItem|null
9690
*/
97-
public function get($value)
91+
public function get(string $value)
9892
{
9993
return $this->items[$value] ?? $this->items[explode('/', $value)[0].'/*'] ?? $this->items['*/*'] ?? $this->items['*'] ?? null;
10094
}
@@ -127,11 +121,9 @@ public function all()
127121
/**
128122
* Filters items on their value using given regex.
129123
*
130-
* @param string $pattern
131-
*
132124
* @return self
133125
*/
134-
public function filter($pattern)
126+
public function filter(string $pattern)
135127
{
136128
return new self(array_filter($this->items, function (AcceptHeaderItem $item) use ($pattern) {
137129
return preg_match($pattern, $item->getValue());
@@ -153,7 +145,7 @@ public function first()
153145
/**
154146
* Sorts items by descending quality.
155147
*/
156-
private function sort()
148+
private function sort(): void
157149
{
158150
if (!$this->sorted) {
159151
uasort($this->items, function (AcceptHeaderItem $a, AcceptHeaderItem $b) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php
+9-23Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ public function __construct(string $value, array $attributes = [])
3434
/**
3535
* Builds an AcceptHeaderInstance instance from a string.
3636
*
37-
* @param string $itemValue
38-
*
3937
* @return self
4038
*/
41-
public static function fromString($itemValue)
39+
public static function fromString(string $itemValue)
4240
{
4341
$parts = HeaderUtils::split($itemValue, ';=');
4442

@@ -66,11 +64,9 @@ public function __toString()
6664
/**
6765
* Set the item value.
6866
*
69-
* @param string $value
70-
*
7167
* @return $this
7268
*/
73-
public function setValue($value)
69+
public function setValue(string $value)
7470
{
7571
$this->value = $value;
7672

@@ -90,11 +86,9 @@ public function getValue()
9086
/**
9187
* Set the item quality.
9288
*
93-
* @param float $quality
94-
*
9589
* @return $this
9690
*/
97-
public function setQuality($quality)
91+
public function setQuality(float $quality)
9892
{
9993
$this->quality = $quality;
10094

@@ -114,11 +108,9 @@ public function getQuality()
114108
/**
115109
* Set the item index.
116110
*
117-
* @param int $index
118-
*
119111
* @return $this
120112
*/
121-
public function setIndex($index)
113+
public function setIndex(int $index)
122114
{
123115
$this->index = $index;
124116

@@ -138,24 +130,21 @@ public function getIndex()
138130
/**
139131
* Tests if an attribute exists.
140132
*
141-
* @param string $name
142-
*
143133
* @return bool
144134
*/
145-
public function hasAttribute($name)
135+
public function hasAttribute(string $name)
146136
{
147137
return isset($this->attributes[$name]);
148138
}
149139

150140
/**
151141
* Returns an attribute by its name.
152142
*
153-
* @param string $name
154-
* @param mixed $default
143+
* @param mixed $default
155144
*
156145
* @return mixed
157146
*/
158-
public function getAttribute($name, $default = null)
147+
public function getAttribute(string $name, $default = null)
159148
{
160149
return isset($this->attributes[$name]) ? $this->attributes[$name] : $default;
161150
}
@@ -173,17 +162,14 @@ public function getAttributes()
173162
/**
174163
* Set an attribute.
175164
*
176-
* @param string $name
177-
* @param string $value
178-
*
179165
* @return $this
180166
*/
181-
public function setAttribute($name, $value)
167+
public function setAttribute(string $name, string $value)
182168
{
183169
if ('q' === $name) {
184170
$this->quality = (float) $value;
185171
} else {
186-
$this->attributes[$name] = (string) $value;
172+
$this->attributes[$name] = $value;
187173
}
188174

189175
return $this;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/BinaryFileResponse.php
+7-12Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,21 @@ public function __construct($file, int $status = 200, array $headers = [], bool
6666
*
6767
* @return static
6868
*/
69-
public static function create($file = null, $status = 200, $headers = [], $public = true, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
69+
public static function create($file = null, int $status = 200, array $headers = [], bool $public = true, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
7070
{
7171
return new static($file, $status, $headers, $public, $contentDisposition, $autoEtag, $autoLastModified);
7272
}
7373

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
*
8481
* @throws FileException
8582
*/
86-
public function setFile($file, $contentDisposition = null, $autoEtag = false, $autoLastModified = true)
83+
public function setFile($file, string $contentDisposition = null, bool $autoEtag = false, bool $autoLastModified = true)
8784
{
8885
if (!$file instanceof File) {
8986
if ($file instanceof \SplFileInfo) {
@@ -153,7 +150,7 @@ public function setAutoEtag()
153150
*
154151
* @return $this
155152
*/
156-
public function setContentDisposition($disposition, $filename = '', $filenameFallback = '')
153+
public function setContentDisposition(string $disposition, string $filename = '', string $filenameFallback = '')
157154
{
158155
if ('' === $filename) {
159156
$filename = $this->file->getFilename();
@@ -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.');
@@ -346,11 +343,9 @@ public static function trustXSendfileTypeHeader()
346343
* If this is set to true, the file will be unlinked after the request is send
347344
* Note: If the X-Sendfile header is used, the deleteFileAfterSend setting will not be used.
348345
*
349-
* @param bool $shouldDelete
350-
*
351346
* @return $this
352347
*/
353-
public function deleteFileAfterSend($shouldDelete = true)
348+
public function deleteFileAfterSend(bool $shouldDelete = true)
354349
{
355350
$this->deleteFileAfterSend = $shouldDelete;
356351

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Cookie.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ class Cookie
3636
/**
3737
* Creates cookie from raw header string.
3838
*
39-
* @param string $cookie
40-
* @param bool $decode
41-
*
4239
* @return static
4340
*/
44-
public static function fromString($cookie, $decode = false)
41+
public static function fromString(string $cookie, bool $decode = false)
4542
{
4643
$data = [
4744
'expires' => 0,

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/Exception/AccessDeniedException.php
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
class AccessDeniedException extends FileException
2020
{
21-
/**
22-
* @param string $path The path to the accessed file
23-
*/
2421
public function __construct(string $path)
2522
{
2623
parent::__construct(sprintf('The file %s could not be accessed', $path));

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/Exception/FileNotFoundException.php
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
class FileNotFoundException extends FileException
2020
{
21-
/**
22-
* @param string $path The path to the file that was not found
23-
*/
2421
public function __construct(string $path)
2522
{
2623
parent::__construct(sprintf('The file "%s" does not exist', $path));

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/File.php
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,11 @@ public function getMimeType()
7676
/**
7777
* Moves the file to a new location.
7878
*
79-
* @param string $directory The destination folder
80-
* @param string $name The new file name
81-
*
8279
* @return self A File object representing the new file
8380
*
8481
* @throws FileException if the target file could not be created
8582
*/
86-
public function move($directory, $name = null)
83+
public function move(string $directory, string $name = null)
8784
{
8885
$target = $this->getTargetFile($directory, $name);
8986

@@ -99,7 +96,10 @@ public function move($directory, $name = null)
9996
return $target;
10097
}
10198

102-
protected function getTargetFile($directory, $name = null)
99+
/**
100+
* @return self
101+
*/
102+
protected function getTargetFile(string $directory, string $name = null)
103103
{
104104
if (!is_dir($directory)) {
105105
if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
@@ -117,11 +117,9 @@ protected function getTargetFile($directory, $name = null)
117117
/**
118118
* Returns locale independent base name of the given path.
119119
*
120-
* @param string $name The new file name
121-
*
122-
* @return string containing
120+
* @return string
123121
*/
124-
protected function getName($name)
122+
protected function getName(string $name)
125123
{
126124
$originalName = str_replace('\\', '/', $name);
127125
$pos = strrpos($originalName, '/');

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/UploadedFile.php
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,11 @@ public function isValid()
164164
/**
165165
* Moves the file to a new location.
166166
*
167-
* @param string $directory The destination folder
168-
* @param string $name The new file name
169-
*
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
173170
*/
174-
public function move($directory, $name = null)
171+
public function move(string $directory, string $name = null)
175172
{
176173
if ($this->isValid()) {
177174
if ($this->test) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/FileBag.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FileBag extends ParameterBag
2424
private static $fileKeys = ['error', 'name', 'size', 'tmp_name', 'type'];
2525

2626
/**
27-
* @param array $parameters An array of HTTP files
27+
* @param array|UploadedFile[] $parameters An array of HTTP files
2828
*/
2929
public function __construct(array $parameters = [])
3030
{
@@ -43,7 +43,7 @@ public function replace(array $files = [])
4343
/**
4444
* {@inheritdoc}
4545
*/
46-
public function set($key, $value)
46+
public function set(string $key, $value)
4747
{
4848
if (!\is_array($value) && !$value instanceof UploadedFile) {
4949
throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');

0 commit comments

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