Skip to content

Commit 90e29e4

Browse files
authored
Improved array typing
Thanks to @szepeviktor
1 parent 6bbe759 commit 90e29e4

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

src/Encoding/Json.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public function __construct(Reader $reader)
3030
}
3131

3232
/**
33+
* @return array<mixed, mixed>
34+
*
3335
* @throws JsonException
3436
* @throws ReaderError
3537
*/

src/Encoding/JsonDecoder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ interface JsonDecoder
1919
/**
2020
* Decodes a json string into an associative array.
2121
*
22+
* @return array<mixed, mixed>
23+
*
2224
* @throws JsonException when parsing fails
2325
*/
2426
public function decode(): array;

src/Headers.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414
*/
1515
class Headers
1616
{
17+
/**
18+
* @var array<string, string>
19+
*/
1720
private array $headers;
1821

1922
/**
2023
* @internal You should not use this api
24+
*
25+
* @param list<string> $lines
2126
*/
2227
public static function fromLines(array &$lines): Headers
2328
{
@@ -35,6 +40,9 @@ public static function fromLines(array &$lines): Headers
3540
return $headers;
3641
}
3742

43+
/**
44+
* @param array<string, string> $headers
45+
*/
3846
public static function fromMap(array $headers): Headers
3947
{
4048
$self = new self();
@@ -83,6 +91,9 @@ public function has(string $name): bool
8391
return array_key_exists($name, $this->headers);
8492
}
8593

94+
/**
95+
* @return list<string>
96+
*/
8697
public function map(callable $callable): array
8798
{
8899
$arr = [];
@@ -93,6 +104,9 @@ public function map(callable $callable): array
93104
return $arr;
94105
}
95106

107+
/**
108+
* @return array<string, string>
109+
*/
96110
public function filter(callable $callable): array
97111
{
98112
$arr = [];
@@ -105,11 +119,17 @@ public function filter(callable $callable): array
105119
return $arr;
106120
}
107121

122+
/**
123+
* @return list<string>
124+
*/
108125
public function toArray(): array
109126
{
110127
return $this->map(fn (string $value, string $name) => $name.': '.$value);
111128
}
112129

130+
/**
131+
* @return array<string, string>
132+
*/
113133
public function toMap(): array
114134
{
115135
return $this->headers;

src/HttpPartialResponse.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ final class HttpPartialResponse implements PartialResponse
2121
private Headers $headers;
2222

2323
/**
24-
* @return HttpPartialResponse[]
24+
* @param list<string> $lines
25+
*
26+
* @return list<HttpPartialResponse>
2527
*/
2628
public static function parseLines(array $lines): array
2729
{
2830
$partials = [];
29-
while (count($lines) > 0) {
31+
while ($lines !== []) {
3032
$line = array_shift($lines);
3133
if (strpos($line, 'HTTP') === 0) {
3234
$status = Status::fromStatusLine($line);

src/Redirected.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface Redirected
1919
*
2020
* The body of those responses is not available.
2121
*
22-
* @return PartialResponse[]
22+
* @return list<PartialResponse>
2323
*/
2424
public function previousResponses(): array;
2525
}

src/RedirectedHttpResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class RedirectedHttpResponse implements Response, Redirected
1818
{
1919
private Response $response;
2020
/**
21-
* @var PartialResponse[]
21+
* @var list<PartialResponse>
2222
*/
2323
private array $previous;
2424

0 commit comments

Comments
 (0)