Skip to content

Commit ef1d7ce

Browse files
committed
Added parameter and return type information to callable in PHP docs. Made some other minor improvements
1 parent c490c76 commit ef1d7ce

10 files changed

+83
-66
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
end_of_line = lf
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitattributes

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
.gitattributes export-ignore
2-
.gitignore export-ignore
2+
.gitignore export-ignore
3+
4+
*.php eol=lf
5+
*.json eol=lf

phpstan.neon

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ parameters:
55
level: 6
66

77
treatPhpDocTypesAsCertain: false
8+
checkMissingCallableSignature: true
89

910
ignoreErrors:
1011
- message: '#Property .* has no type specified.#'

src/Robtimus/Multipart/Multipart.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class Multipart
2222
private $contentType;
2323

2424
/**
25-
* @var array<string|resource|callable> the parts that form this multipart object.
25+
* @var array<string|resource|callable(int):string> the parts that form this multipart object.
2626
*/
2727
private $parts = [];
2828

@@ -188,11 +188,11 @@ final protected function endHeaders()
188188
/**
189189
* Adds the content of a part.
190190
*
191-
* @param string|resource|callable $content The content.
192-
* If it's a callable it should take a length argument
193-
* and return a string that is not larger than the input.
194-
* @param int $length The length of the part, or -1 if not known.
195-
* Ignored if the part is a string.
191+
* @param string|resource|callable(int):string $content The content.
192+
* If it's a callable it should take a length argument
193+
* and return a string that is not larger than the input.
194+
* @param int $length The length of the part, or -1 if not known.
195+
* Ignored if the part is a string.
196196
*
197197
* @return void
198198
*/
@@ -251,11 +251,11 @@ final public function isFinished()
251251
/**
252252
* Adds a piece of a part.
253253
*
254-
* @param string|resource|callable $part The part to add.
255-
* If it's a callable it should take a length argument
256-
* and return a string that is not larger than the input.
257-
* @param int $length The length of the part, or -1 if not known.
258-
* Ignored if the part is a string.
254+
* @param string|resource|callable(int):string $part The part to add.
255+
* If it's a callable it should take a length argument
256+
* and return a string that is not larger than the input.
257+
* @param int $length The length of the part, or -1 if not known.
258+
* Ignored if the part is a string.
259259
*
260260
* @return void
261261
*/
@@ -345,16 +345,16 @@ private function doReadFromPart($length)
345345
$result = $length === 0 ? '' : substr($part, $this->partIndex, $length);
346346
$this->partIndex += $length;
347347
return $result;
348-
} elseif (is_resource($this->parts[$this->index])) {
348+
} elseif (is_resource($part)) {
349349
$result = @fread($part, $length);
350350
if ($result === false) {
351351
throw new \ErrorException(error_get_last()['message']);
352352
}
353353
return $result;
354-
} elseif (is_callable($this->parts[$this->index])) {
354+
} elseif (is_callable($part)) {
355355
return call_user_func($part, $length);
356356
} else {
357-
throw new \UnexpectedValueException('non-supported part type: ' . gettype($this->parts[$this->index]));
357+
throw new \UnexpectedValueException('non-supported part type: ' . gettype($part));
358358
}
359359
}
360360

src/Robtimus/Multipart/MultipartAlternative.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public function addMultipart(Multipart $multipart)
3636
/**
3737
* Adds an alternative.
3838
*
39-
* @param string|resource|callable $content The part's content.
40-
* If it's a callable it should take a length argument
41-
* and return a string that is not larger than the input.
42-
* @param string $contentType The part's content type.
43-
* @param int $contentLength The part's content length, or -1 if not known.
44-
* Ignored if the part's content is a string.
45-
* @param string $contentTransferEncoding The optional content transfer encoding.
39+
* @param string|resource|callable(int):string $content The part's content.
40+
* If it's a callable it should take a length argument
41+
* and return a string that is not larger than the input.
42+
* @param string $contentType The part's content type.
43+
* @param int $contentLength The part's content length, or -1 if not known.
44+
* Ignored if the part's content is a string.
45+
* @param string $contentTransferEncoding The optional content transfer encoding.
4646
*
4747
* @return MultipartAlternative this object.
4848
*/

src/Robtimus/Multipart/MultipartFormData.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ public function addValue($name, $value)
4545
/**
4646
* Adds a file parameter.
4747
*
48-
* @param string $name The parameter name.
49-
* @param string $filename The name of the file.
50-
* @param string|resource|callable $content The file's content.
51-
* If it's a callable it should take a length argument
52-
* and return a string that is not larger than the input.
53-
* @param string $contentType The file's content type.
54-
* @param int $contentLength The file's content length, or -1 if not known.
55-
* Ignored if the file's content is a string.
48+
* @param string $name The parameter name.
49+
* @param string $filename The name of the file.
50+
* @param string|resource|callable(int):string $content The file's content.
51+
* If it's a callable it should take a length argument
52+
* and return a string that is not larger than the input.
53+
* @param string $contentType The file's content type.
54+
* @param int $contentLength The file's content length, or -1 if not known.
55+
* Ignored if the file's content is a string.
5656
*
5757
* @return MultipartFormData this object.
5858
*/

src/Robtimus/Multipart/MultipartMixed.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public function addMultipart(Multipart $multipart)
3636
/**
3737
* Adds a part.
3838
*
39-
* @param string|resource|callable $content The part's content.
40-
* If it's a callable it should take a length argument
41-
* and return a string that is not larger than the input.
42-
* @param string $contentType The part's content type.
43-
* @param int $contentLength The part's content length, or -1 if not known.
44-
* Ignored if the part's content is a string.
45-
* @param string $contentTransferEncoding The optional content transfer encoding.
39+
* @param string|resource|callable(int):string $content The part's content.
40+
* If it's a callable it should take a length argument
41+
* and return a string that is not larger than the input.
42+
* @param string $contentType The part's content type.
43+
* @param int $contentLength The part's content length, or -1 if not known.
44+
* Ignored if the part's content is a string.
45+
* @param string $contentTransferEncoding The optional content transfer encoding.
4646
*
4747
* @return MultipartMixed this object.
4848
*/
@@ -68,14 +68,14 @@ public function addPart($content, $contentType, $contentLength = -1, $contentTra
6868
/**
6969
* Adds a file attachment.
7070
*
71-
* @param string $filename The name of the file.
72-
* @param string|resource|callable $content The file's content.
73-
* If it's a callable it should take a length argument
74-
* and return a string that is not larger than the input.
75-
* @param string $contentType The file's content type.
76-
* @param int $contentLength The file's content length, or -1 if not known.
77-
* Ignored if the file's content is a string.
78-
* @param string $contentTransferEncoding The optional content transfer encoding.
71+
* @param string $filename The name of the file.
72+
* @param string|resource|callable(int):string $content The file's content.
73+
* If it's a callable it should take a length argument
74+
* and return a string that is not larger than the input.
75+
* @param string $contentType The file's content type.
76+
* @param int $contentLength The file's content length, or -1 if not known.
77+
* Ignored if the file's content is a string.
78+
* @param string $contentTransferEncoding The optional content transfer encoding.
7979
*
8080
* @return MultipartMixed this object.
8181
*/

src/Robtimus/Multipart/MultipartRelated.php

+16-16
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public function __construct($boundary = '')
2323
/**
2424
* Adds a part.
2525
*
26-
* @param string|resource|callable $content The part's content.
27-
* If it's a callable it should take a length argument
28-
* and return a string that is not larger than the input.
29-
* @param string $contentType The part's content type.
30-
* @param int $contentLength The part's content length, or -1 if not known.
31-
* Ignored if the part's content is a string.
32-
* @param string $contentTransferEncoding The optional content transfer encoding.
26+
* @param string|resource|callable(int):string $content The part's content.
27+
* If it's a callable it should take a length argument
28+
* and return a string that is not larger than the input.
29+
* @param string $contentType The part's content type.
30+
* @param int $contentLength The part's content length, or -1 if not known.
31+
* Ignored if the part's content is a string.
32+
* @param string $contentTransferEncoding The optional content transfer encoding.
3333
*
3434
* @return MultipartRelated this object.
3535
*/
@@ -55,15 +55,15 @@ public function addPart($content, $contentType, $contentLength = -1, $contentTra
5555
/**
5656
* Adds an inline file.
5757
*
58-
* @param string $contentID The content id of the file.
59-
* @param string $filename The name of the file.
60-
* @param string|resource|callable $content The file's content.
61-
* If it's a callable it should take a length argument
62-
* and return a string that is not larger than the input.
63-
* @param string $contentType The file's content type.
64-
* @param int $contentLength The file's content length, or -1 if not known.
65-
* Ignored if the file's content is a string.
66-
* @param string $contentTransferEncoding The optional content transfer encoding.
58+
* @param string $contentID The content id of the file.
59+
* @param string $filename The name of the file.
60+
* @param string|resource|callable(int):string $content The file's content.
61+
* If it's a callable it should take a length argument
62+
* and return a string that is not larger than the input.
63+
* @param string $contentType The file's content type.
64+
* @param int $contentLength The file's content length, or -1 if not known.
65+
* Ignored if the file's content is a string.
66+
* @param string $contentTransferEncoding The optional content transfer encoding.
6767
*
6868
* @return MultipartRelated this object.
6969
*/

src/Robtimus/Multipart/Util.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public static function validateNonEmptyString(&$input, $name, $message = '')
9494
/**
9595
* Validates that an input value can be used for streaming.
9696
*
97-
* @param string|resource|callable $input The input to validate.
98-
* @param string $name The name of the input value.
99-
* @param string $message An optional message to show if the value cannot be used for streaming.
97+
* @param string|resource|callable(int):string $input The input to validate.
98+
* @param string $name The name of the input value.
99+
* @param string $message An optional message to show if the value cannot be used for streaming.
100100
*
101101
* @return void
102102
*
@@ -115,7 +115,7 @@ public static function validateStreamable(&$input, $name, $message = '')
115115
* @param string $name The name of the input value.
116116
* @param string $message An optional message for the exception.
117117
*
118-
* @return void
118+
* @return never
119119
*
120120
* @throws \InvalidArgumentException always.
121121
*/

tests/Robtimus/Multipart/MultipartFormDataTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ public function testUploadMixedWithDuplicateParameterNames()
495495
$this->assertEquals(['value1', 'value2'], $response->form->name);
496496
}
497497

498-
private function skipUploadIfNeeded() {
498+
private function skipUploadIfNeeded()
499+
{
499500
$skipUpload = $this->getConfigValue('http.upload.skip', false);
500501
if ($skipUpload === true) {
501502
$this->markTestSkipped('HTTP uploads skipped');

0 commit comments

Comments
 (0)