Skip to content

Commit ead419b

Browse files
julien57nicolas-grekas
authored andcommitted
add type-hints
1 parent 9fec71e commit ead419b

Some content is hidden

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

42 files changed

+207
-450
lines changed

src/Symfony/Component/HttpFoundation/AcceptHeader.php

Lines changed: 5 additions & 13 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());

src/Symfony/Component/HttpFoundation/AcceptHeaderItem.php

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ 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
{
43-
$parts = HeaderUtils::split($itemValue, ';=');
41+
$parts = HeaderUtils::split($itemValue ?? '', ';=');
4442

4543
$part = array_shift($parts);
4644
$attributes = HeaderUtils::combine($parts);
@@ -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

Lines changed: 6 additions & 11 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();
@@ -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

Lines 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/File.php

Lines changed: 3 additions & 8 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

@@ -102,7 +99,7 @@ public function move($directory, $name = null)
10299
/**
103100
* @return self
104101
*/
105-
protected function getTargetFile($directory, $name = null)
102+
protected function getTargetFile(string $directory, string $name = null)
106103
{
107104
if (!is_dir($directory)) {
108105
if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
@@ -120,11 +117,9 @@ protected function getTargetFile($directory, $name = null)
120117
/**
121118
* Returns locale independent base name of the given path.
122119
*
123-
* @param string $name The new file name
124-
*
125120
* @return string
126121
*/
127-
protected function getName($name)
122+
protected function getName(string $name)
128123
{
129124
$originalName = str_replace('\\', '/', $name);
130125
$pos = strrpos($originalName, '/');

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

Lines 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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy