Skip to content

Commit ddf9287

Browse files
fixing CI complaints (#1666)
* fixing psalm complaints use rector (and psalm) to add Override attributes, and add symfony polyfill to provide Override in earlier php versions * fixing more psalm complaints * more fixes * adding stubs for deptrac there are some things in our code that deptrac doesn't understand or are missing for some php versions. stub them to quieten all those violation warnings * why not cache invalid :( * display tools versions * fix tools cache key * changing cache key * dont complain about unused psalm suppressions * suppress invalid attribute * quieten phpstan php8.5 complaints * revert previous commit...now other php versions complain about an unused ignore :( * revert typecasting in metrics aggregators * Update src/Contrib/Otlp/ProtobufSerializer.php Co-authored-by: Chris Lightfoot-Wild <github-clw@wild.me.uk> * remove override stub and use the polyfill from deptrac --------- Co-authored-by: Chris Lightfoot-Wild <github-clw@wild.me.uk>
1 parent 196f3a1 commit ddf9287

13 files changed

+30
-2
lines changed

HttpEndpointResolver.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public static function create(?FactoryResolverInterface $httpFactoryResolver = n
3737
return new self($httpFactoryResolver);
3838
}
3939

40+
#[\Override]
4041
public function resolve(string $endpoint, string $signal): UriInterface
4142
{
4243
$components = self::parseEndpoint($endpoint);
@@ -50,6 +51,7 @@ public function resolve(string $endpoint, string $signal): UriInterface
5051
);
5152
}
5253

54+
#[\Override]
5355
public function resolveToString(string $endpoint, string $signal): string
5456
{
5557
return (string) $this->resolve($endpoint, $signal);

LogsExporter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function __construct(private TransportInterface $transport)
3636
/**
3737
* @param iterable<ReadableLogRecord> $batch
3838
*/
39+
#[\Override]
3940
public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface
4041
{
4142
return $this->transport
@@ -70,11 +71,13 @@ public function export(iterable $batch, ?CancellationInterface $cancellation = n
7071
});
7172
}
7273

74+
#[\Override]
7375
public function forceFlush(?CancellationInterface $cancellation = null): bool
7476
{
7577
return $this->transport->forceFlush($cancellation);
7678
}
7779

80+
#[\Override]
7881
public function shutdown(?CancellationInterface $cancellation = null): bool
7982
{
8083
return $this->transport->shutdown($cancellation);

LogsExporterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function __construct(private readonly ?TransportFactoryInterface $transpo
2525
/**
2626
* @psalm-suppress ArgumentTypeCoercion
2727
*/
28+
#[\Override]
2829
public function create(): LogRecordExporterInterface
2930
{
3031
$protocol = Configuration::has(Variables::OTEL_EXPORTER_OTLP_LOGS_PROTOCOL)

MetricConverter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ private function convertHistogramDataPoint(SDK\Metrics\Data\HistogramDataPoint $
214214
return $pHistogramDataPoint;
215215
}
216216

217+
/**
218+
* @psalm-suppress PossiblyFalseArgument
219+
*/
217220
private function convertExemplar(SDK\Metrics\Data\Exemplar $exemplar): Exemplar
218221
{
219222
$pExemplar = new Exemplar();

MetricExporter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ public function __construct(
3737
$this->serializer = ProtobufSerializer::forTransport($this->transport);
3838
}
3939

40+
#[\Override]
4041
public function temporality(MetricMetadataInterface $metric): Temporality|string|null
4142
{
4243
return $this->temporality ?? $metric->temporality();
4344
}
4445

46+
#[\Override]
4547
public function export(iterable $batch): bool
4648
{
4749
return $this->transport
@@ -77,11 +79,13 @@ public function export(iterable $batch): bool
7779
->await();
7880
}
7981

82+
#[\Override]
8083
public function shutdown(): bool
8184
{
8285
return $this->transport->shutdown();
8386
}
8487

88+
#[\Override]
8589
public function forceFlush(): bool
8690
{
8791
return $this->transport->forceFlush();

MetricExporterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function __construct(private readonly ?TransportFactoryInterface $transpo
2626
/**
2727
* @psalm-suppress ArgumentTypeCoercion
2828
*/
29+
#[\Override]
2930
public function create(): MetricExporterInterface
3031
{
3132
$protocol = Configuration::has(Variables::OTEL_EXPORTER_OTLP_METRICS_PROTOCOL)

OtlpHttpTransportFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class OtlpHttpTransportFactory implements TransportFactoryInterface
1212
{
1313
private const DEFAULT_COMPRESSION = 'none';
1414

15+
#[\Override]
1516
public function create(
1617
string $endpoint,
1718
string $contentType,

ProtobufSerializer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use const JSON_UNESCAPED_SLASHES;
2020
use const JSON_UNESCAPED_UNICODE;
2121
use function lcfirst;
22+
use OpenTelemetry\API\Behavior\LogsMessagesTrait;
2223
use OpenTelemetry\SDK\Common\Export\TransportInterface;
2324
use function property_exists;
2425
use function sprintf;
@@ -30,6 +31,8 @@
3031
*/
3132
final class ProtobufSerializer
3233
{
34+
use LogsMessagesTrait;
35+
3336
private function __construct(private readonly string $contentType)
3437
{
3538
}
@@ -117,11 +120,14 @@ private static function serializeToJsonString(Message $message): string
117120
return $payload;
118121
}
119122

120-
$data = json_decode($payload);
123+
$data = json_decode((string) $payload);
121124
unset($payload);
122125
self::traverseDescriptor($data, $desc);
123126

124-
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
127+
$encoded = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
128+
assert($encoded !== false);
129+
130+
return $encoded;
125131
}
126132

127133
private static function traverseDescriptor(object $data, Descriptor $desc): void

SpanExporter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function __construct(private TransportInterface $transport)
3232
$this->serializer = ProtobufSerializer::forTransport($this->transport);
3333
}
3434

35+
#[\Override]
3536
public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface
3637
{
3738
return $this->transport
@@ -66,11 +67,13 @@ public function export(iterable $batch, ?CancellationInterface $cancellation = n
6667
});
6768
}
6869

70+
#[\Override]
6971
public function shutdown(?CancellationInterface $cancellation = null): bool
7072
{
7173
return $this->transport->shutdown($cancellation);
7274
}
7375

76+
#[\Override]
7477
public function forceFlush(?CancellationInterface $cancellation = null): bool
7578
{
7679
return $this->transport->forceFlush($cancellation);

SpanExporterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function __construct(private readonly ?TransportFactoryInterface $transpo
2828
/**
2929
* @psalm-suppress ArgumentTypeCoercion
3030
*/
31+
#[\Override]
3132
public function create(): SpanExporterInterface
3233
{
3334
$transport = $this->buildTransport();

0 commit comments

Comments
 (0)