8000 add type-hints · symfony/symfony@2181739 · GitHub
[go: up one dir, main page]

Skip to content
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 2181739

Browse files
julien57nicolas-grekas
julien57
authored andcommitted
add type-hints
1 parent 2a9359d commit 2181739

Some content is hidden

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

45 files changed

+196
-503
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 F438 = 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: 8 additions & 22 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,12 +162,9 @@ 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;

src/Symfony/Component/HttpFoundation/BinaryFileResponse.php

Lines changed: 5 additions & 10 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, 10000 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();
@@ -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 & 6 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,
@@ -74,8 +71,6 @@ public static function create(string $name, string $value = null, $expire = 0, ?
7471
}
7572

7673
/**
77-
* @param string $name The name of the cookie
78-
* @param string|null $value The value of the cookie
7974
* @param int|string|\DateTimeInterface $expire The time the cookie expires
8075
* @param string $path The path on the server in which the cookie will be available on
8176
* @param string|null $domain The domain that the cookie is available to

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

Lines 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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ class File extends \SplFileInfo
2525
/**
2626
* Constructs a new file from the given path.
2727
*
28-
* @param string $path The path to the file
29-
* @param bool $checkPath Whether to check the path or not
30-
*
3128
* @throws FileNotFoundException If the given path is not a file
3229
*/
3330
public function __construct(string $path, bool $checkPath = true)
@@ -76,14 +73,11 @@ public function getMimeType()
7673
/**
7774
* Moves the file to a new location.
7875
*
79-
* @param string $directory The destination folder
80-
* @param string $name The new file name
81-
*
8276
* @return self A File object representing the new file
8377
*
8478
* @throws FileException if the target file could not be created
8579
*/
86-
public function move($directory, $name = null)
80+
public function move(string $directory, string $name = null)
8781
{
8882
$target = $this->getTargetFile($directory, $name);
8983

@@ -117,11 +111,9 @@ protected function getTargetFile($directory, $name = null)
117111
/**
118112
* Returns locale independent base name of the given path.
119113
*
120-
* @param string $name The new file name
121-
*
122114
* @return string containing
123115
*/
124-
protected function getName($name)
116+
protected function getName(string $name)
125117
{
126118
$originalName = str_replace('\\', '/', $name);
127119
$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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class FileBag extends ParameterBag
2323
{
2424
private static $fileKeys = ['error', 'name', 'size', 'tmp_name', 'type'];
2525

26-
/**
27-
* @param array $parameters An array of HTTP files
28-
*/
2926
public function __construct(array $parameters = [])
3027
{
3128
$this->replace($parameters);
@@ -43,7 +40,7 @@ public function replace(array $files = [])
4340
/**
4441
* {@inheritdoc}
4542
*/
46-
public function set($key, $value)
43+
public function set(string $key, $value)
4744
{
4845
if (!\is_array($value) && !$value instanceof UploadedFile) {
4946
throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');

0 commit comments

Comments
 (0)
0