Skip to content

Commit 682e582

Browse files
committed
blah
1 parent e15ecaa commit 682e582

13 files changed

+85
-75
lines changed

phpstan-baseline.neon

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Parameter \\#2 \\$data of method Lcobucci\\\\Kafka\\\\Protocol\\\\Buffer\\:\\:unpack\\(\\) expects string, mixed given\\.$#"
5-
count: 5
6-
path: src/Protocol/Buffer.php
4+
message: "#^Cannot use array destructuring on array\\<int\\|string, array\\<int, array\\<int, int\\|Lcobucci\\\\Kafka\\\\Protocol\\\\API\\\\Request\\|string\\>\\|int\\|Lcobucci\\\\Kafka\\\\Protocol\\\\API\\\\Request\\|React\\\\Promise\\\\Deferred\\|string\\>\\|int\\|React\\\\Promise\\\\Deferred\\>\\|int\\.$#"
5+
count: 1
6+
path: src/Client/Channel.php
7+
8+
-
9+
message: "#^Parameter \\#1 \\$errorCode of class Lcobucci\\\\Kafka\\\\Protocol\\\\API\\\\ApiVersionsResponse constructor expects int, mixed given\\.$#"
10+
count: 1
11+
path: src/Protocol/API/ApiVersionsResponse.php
12+
13+
-
14+
message: "#^Parameter \\#2 \\$apiVersions of class Lcobucci\\\\Kafka\\\\Protocol\\\\API\\\\ApiVersionsResponse constructor expects array\\<int, array\\{api_key\\: int, min_version\\: int, max_version\\: int\\}\\>, mixed given\\.$#"
15+
count: 1
16+
path: src/Protocol/API/ApiVersionsResponse.php
17+
18+
-
19+
message: "#^Parameter \\#3 \\$throttleTime of class Lcobucci\\\\Kafka\\\\Protocol\\\\API\\\\ApiVersionsResponse constructor expects int, mixed given\\.$#"
20+
count: 1
21+
path: src/Protocol/API/ApiVersionsResponse.php
22+
23+
-
24+
message: "#^Parameter \\#1 \\$errorCode of class Lcobucci\\\\Kafka\\\\Protocol\\\\API\\\\MetadataResponse constructor expects int, mixed given\\.$#"
25+
count: 1
26+
path: src/Protocol/API/MetadataResponse.php
27+
28+
-
29+
message: "#^Parameter \\#2 \\$apiVersions of class Lcobucci\\\\Kafka\\\\Protocol\\\\API\\\\MetadataResponse constructor expects array\\<int, array\\{api_key\\: int, min_version\\: int, max_version\\: int\\}\\>, mixed given\\.$#"
30+
count: 1
31+
path: src/Protocol/API/MetadataResponse.php
32+
33+
-
34+
message: "#^Parameter \\#3 \\$throttleTime of class Lcobucci\\\\Kafka\\\\Protocol\\\\API\\\\MetadataResponse constructor expects int, mixed given\\.$#"
35+
count: 1
36+
path: src/Protocol/API/MetadataResponse.php
37+
38+
-
39+
message: "#^Parameter \\#1 \\$definition of method Lcobucci\\\\Kafka\\\\Protocol\\\\Schema\\\\Parser\\:\\:parse\\(\\) expects array\\<string, array\\<string, mixed\\>\\|class\\-string\\<Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\>\\>, array\\<string, array\\<string, mixed\\>\\|string\\> given\\.$#"
40+
count: 1
41+
path: src/Protocol/API/Request.php
42+
43+
-
44+
message: "#^Parameter \\#1 \\$definition of method Lcobucci\\\\Kafka\\\\Protocol\\\\Schema\\\\Parser\\:\\:parse\\(\\) expects array\\<string, array\\<string, mixed\\>\\|class\\-string\\<Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\>\\>, array\\<string, array\\<string, mixed\\>\\|string\\> given\\.$#"
45+
count: 1
46+
path: src/Protocol/API/Response.php
747

848
-
949
message: "#^Parameter \\#1 \\$data of method Lcobucci\\\\Kafka\\\\Protocol\\\\Schema\\:\\:validateField\\(\\) expects array\\<string, mixed\\>, mixed given\\.$#"
@@ -15,6 +55,21 @@ parameters:
1555
count: 1
1656
path: src/Protocol/Schema.php
1757

58+
-
59+
message: "#^Parameter \\#1 \\$definition of method Lcobucci\\\\Kafka\\\\Protocol\\\\Schema\\\\Parser\\:\\:parse\\(\\) expects array\\<string, array\\<string, mixed\\>\\|class\\-string\\<Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\>\\>, array\\<string, mixed\\> given\\.$#"
60+
count: 1
61+
path: src/Protocol/Schema/Parser.php
62+
63+
-
64+
message: "#^Parameter \\#1 \\$fieldDefinition of method Lcobucci\\\\Kafka\\\\Protocol\\\\Schema\\\\Parser\\:\\:parseFieldType\\(\\) expects array\\<string, mixed\\>\\|class\\-string\\<Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\>, mixed given\\.$#"
65+
count: 1
66+
path: src/Protocol/Schema/Parser.php
67+
68+
-
69+
message: "#^Parameter \\#2 \\$nullable of class Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\\\ArrayOf constructor expects bool, mixed given\\.$#"
70+
count: 1
71+
path: src/Protocol/Schema/Parser.php
72+
1873
-
1974
message: "#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
2075
count: 1
@@ -65,11 +120,6 @@ parameters:
65120
count: 1
66121
path: src/Protocol/Type/Int8.php
67122

68-
-
69-
message: "#^Parameter \\#1 \\$content of static method Lcobucci\\\\Kafka\\\\Protocol\\\\Buffer\\:\\:fromContent\\(\\) expects string, mixed given\\.$#"
70-
count: 1
71-
path: src/Protocol/Type/NonNullableBytes.php
72-
73123
-
74124
message: "#^Parameter \\#1 \\$data of method Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\:\\:guardClass\\(\\) expects object\\|null, mixed given\\.$#"
75125
count: 1
@@ -80,11 +130,6 @@ parameters:
80130
count: 2
81131
path: src/Protocol/Type/NonNullableBytes.php
82132

83-
-
84-
message: "#^Method Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\\\NonNullableString\\:\\:read\\(\\) should return string but returns mixed\\.$#"
85-
count: 1
86-
path: src/Protocol/Type/NonNullableString.php
87-
88133
-
89134
message: "#^Parameter \\#1 \\$data of method Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\:\\:guardLength\\(\\) expects string\\|null, mixed given\\.$#"
90135
count: 1
@@ -100,21 +145,11 @@ parameters:
100145
count: 1
101146
path: src/Protocol/Type/NonNullableString.php
102147

103-
-
104-
message: "#^Parameter \\#1 \\$content of static method Lcobucci\\\\Kafka\\\\Protocol\\\\Buffer\\:\\:fromContent\\(\\) expects string, mixed given\\.$#"
105-
count: 1
106-
path: src/Protocol/Type/NullableBytes.php
107-
108148
-
109149
message: "#^Parameter \\#1 \\$data of method Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\:\\:guardClass\\(\\) expects object\\|null, mixed given\\.$#"
110150
count: 1
111151
path: src/Protocol/Type/NullableBytes.php
112152

113-
-
114-
message: "#^Method Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\\\NullableString\\:\\:read\\(\\) should return string\\|null but returns mixed\\.$#"
115-
count: 1
116-
path: src/Protocol/Type/NullableString.php
117-
118153
-
119154
message: "#^Parameter \\#1 \\$data of method Lcobucci\\\\Kafka\\\\Protocol\\\\Type\\:\\:guardLength\\(\\) expects string\\|null, mixed given\\.$#"
120155
count: 1

src/Client/Channel.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
namespace Lcobucci\Kafka\Client;
55

6-
use Closure;
76
use Lcobucci\Kafka\Node;
87
use Lcobucci\Kafka\Protocol\API\Request;
98
use Lcobucci\Kafka\Protocol\API\RequestHeaders;
@@ -25,9 +24,9 @@
2524

2625
final class Channel
2726
{
28-
/** @var SplPriorityQueue<int, array{0: array{0: Request, 1: int, 2: string}, 1: Deferred}> */
27+
/** @var SplPriorityQueue<int, array{array{Request, int, string}, Deferred}> */
2928
private SplPriorityQueue $processingQueue;
30-
/** @var SplQueue<array{0: RequestHeaders, 1: Deferred}> */
29+
/** @var SplQueue<array{RequestHeaders, Deferred}> */
3130
private SplQueue $inFlightQueue;
3231
private ?ConnectionInterface $connection = null;
3332
private readonly LoopInterface $loop;
@@ -36,9 +35,9 @@ public function __construct(
3635
private ConnectorInterface $connector,
3736
private LoggerInterface $logger,
3837
private Parser $schemaParser,
39-
private Node $node
38+
private Node $node,
4039
) {
41-
$this->loop = Loop::get();
40+
$this->loop = Loop::get();
4241
$this->processingQueue = new SplPriorityQueue();
4342
$this->inFlightQueue = new SplQueue();
4443
}
@@ -71,11 +70,11 @@ private function connect(): void
7170
function (Throwable $throwable): void {
7271
$this->logger->error(
7372
'Error while connecting to node #' . $this->node->id,
74-
['node' => $this->node, 'exception' => $throwable]
73+
['node' => $this->node, 'exception' => $throwable],
7574
);
7675

7776
$this->loop->addTimer(1, $this->connect(...));
78-
}
77+
},
7978
);
8079
}
8180

@@ -107,7 +106,7 @@ public function processQueue(): void
107106
$this->inFlightQueue->enqueue([$headers, $deferred]);
108107
}
109108

110-
$this->loop->futureTick([$this, 'processQueue']);
109+
$this->loop->futureTick($this->processQueue(...));
111110
}
112111

113112
private function sendMessage(Request $request, int $correlation, string $client): RequestHeaders
@@ -117,7 +116,7 @@ private function sendMessage(Request $request, int $correlation, string $client)
117116
$request->highestSupportedVersion(),
118117
$correlation,
119118
$client,
120-
$request->responseClass()::parse(...)
119+
$request->responseClass()::parse(...),
121120
);
122121

123122
$header = $headers->toBuffer($this->schemaParser);

src/Cluster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static function (string $server) use (&$id): Node {
2222

2323
return new Node((string) --$id, $host, (int) $port, null);
2424
},
25-
explode(',', $servers)
25+
explode(',', $servers),
2626
);
2727

2828
return new self(null, $brokers);

src/Producer/Record.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,9 @@
55

66
final class Record
77
{
8-
private string $topic;
9-
10-
private mixed $value;
11-
12-
private mixed $key = null;
13-
14-
/** @var string[]|null */
15-
private ?array $headers = null;
16-
17-
private ?int $partition = null;
18-
19-
private ?int $timestamp = null;
20-
218
/** @param string[]|null $headers */
22-
public function __construct(string $topic, mixed $value, mixed $key = null, ?array $headers = null, ?int $partition = null, ?int $timestamp = null)
9+
public function __construct(private string $topic, private mixed $value, private mixed $key = null, private ?array $headers = null, private ?int $partition = null, private ?int $timestamp = null)
2310
{
24-
$this->topic = $topic;
25-
$this->key = $key;
26-
$this->value = $value;
27-
$this->headers = $headers;
28-
$this->partition = $partition;
29-
$this->timestamp = $timestamp;
3011
}
3112

3213
public function topic(): string

src/Protocol/API/ApiVersionsRequest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
namespace Lcobucci\Kafka\Protocol\API;
55

6-
use Composer\InstalledVersions;
7-
use PackageVersions\Versions;
8-
96
use function array_key_last;
107

118
final class ApiVersionsRequest extends Request

src/Protocol/API/ApiVersionsResponse.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
use Lcobucci\Kafka\Protocol\Type;
77

8-
use function array_key_last;
9-
8+
/** @phpstan-type ApiVersion array{api_key: int, min_version: int, max_version: int} */
109
final class ApiVersionsResponse extends Response
1110
{
1211
private const SCHEMA_VERSIONS = [
@@ -28,7 +27,7 @@ final class ApiVersionsResponse extends Response
2827

2928
private const SCHEMA_V1 = self::SCHEMA_V0 + ['throttle_time_ms' => Type\Int32::class];
3029

31-
/** @param list<array{api_key: int, min_version: int, max_version: int}> $apiVersions */
30+
/** @param list<ApiVersion> $apiVersions */
3231
public function __construct(public int $errorCode, public array $apiVersions, public int $throttleTime)
3332
{
3433
}
@@ -39,7 +38,7 @@ public static function fromArray(array $data): static
3938
return new self(
4039
$data['error_code'],
4140
$data['api_versions'],
42-
$data['throttle_time_ms'] ?? 0
41+
$data['throttle_time_ms'] ?? 0,
4342
);
4443
}
4544

src/Protocol/API/MetadataResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static function fromArray(array $data): static
3636
return new self(
3737
$data['error_code'],
3838
$data['api_versions'],
39-
$data['throttle_time_ms'] ?? 0
39+
$data['throttle_time_ms'] ?? 0,
4040
);
4141
}
4242

src/Protocol/API/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function toBuffer(Parser $schemaParser, int $version): Buffer
2626
/** @return array<string, string|array<string, mixed>> */
2727
abstract public static function schemaDefinition(int $version): array;
2828

29-
/** @return array<string, mixed> $data */
29+
/** @return array<string, mixed> */
3030
abstract public function asArray(int $version): array;
3131

3232
/** @return class-string<Response> */

src/Protocol/API/RequestHeaders.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
public int $apiVersion,
2626
public int $correlationId,
2727
public string $client,
28-
private Closure $responseFactory
28+
private Closure $responseFactory,
2929
) {
3030
}
3131

src/Protocol/API/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
abstract class Response
1010
{
11-
public static function parse(Buffer $buffer, Parser $schemaParser, int $version): self
11+
public static function parse(Buffer $buffer, Parser $schemaParser, int $version): static
1212
{
1313
$schema = $schemaParser->parse(static::schemaDefinition($version));
1414

src/Protocol/Buffer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function write(string $value): void
140140
*
141141
* @throws NotEnoughBytesAllocated When trying to read from an invalid position.
142142
*/
143-
public function read(int $length): mixed
143+
public function read(int $length): string
144144
{
145145
$offset = $this->nextIndex($length);
146146

src/Protocol/Schema/Parser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
final class Parser
1313
{
14-
/** @param array<string, string|array<string, mixed>> $definition */
14+
/** @param array<string, class-string<Type>|array<string, mixed>> $definition */
1515
public function parse(array $definition): Schema
1616
{
1717
return new Schema(...$this->parseFields($definition));
1818
}
1919

2020
/**
21-
* @param array<string, string|array<string, mixed>> $definition
21+
* @param array<string, class-string<Type>|array<string, mixed>> $definition
2222
*
2323
* @return iterable<Field>
2424
*/
@@ -29,7 +29,7 @@ private function parseFields(array $definition): iterable
2929
}
3030
}
3131

32-
/** @param string|array<string, mixed> $fieldDefinition */
32+
/** @param class-string<Type>|array<string, mixed> $fieldDefinition */
3333
private function parseFieldType(string|array $fieldDefinition): Type
3434
{
3535
if (is_string($fieldDefinition)) {
@@ -39,7 +39,7 @@ private function parseFieldType(string|array $fieldDefinition): Type
3939
if (array_key_exists('_items', $fieldDefinition)) {
4040
return new Type\ArrayOf(
4141
$this->parseFieldType($fieldDefinition['_items']),
42-
$fieldDefinition['_nullable'] ?? false
42+
$fieldDefinition['_nullable'] ?? false,
4343
);
4444
}
4545

test.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
require 'vendor/autoload.php';
1515

16-
$loop = Loop::get();
17-
$logger = new Logger('test-channel', [new StreamHandler('php://stderr')]);
16+
$logger = new Logger('test-channel', [new StreamHandler(STDERR)]);
1817

1918
$cluster = Cluster::bootstrap('localhost:9093,localhost:9094');
2019
$channel = new Channel(
@@ -24,12 +23,12 @@
2423
$cluster->brokers[random_int(0, 1)]
2524
);
2625

27-
$loop->addSignal(
26+
Loop::addSignal(
2827
SIGINT,
29-
$listener = static function () use (&$listener, $loop, $channel): void {
28+
static function () use ($channel): void {
3029
$channel->disconnect();
3130

32-
$loop->removeSignal(SIGINT, $listener);
31+
Loop::stop();
3332
}
3433
);
3534

@@ -39,4 +38,4 @@ static function (Response $response) use ($logger): void {
3938
}
4039
);
4140

42-
$loop->run();
41+
Loop::run();

0 commit comments

Comments
 (0)