Skip to content

Commit c723505

Browse files
authored
fixing psalm and rector complaints (#1732)
* suppress some new psalm complaints * apply x2 rector suggested fixes
1 parent d5f5aa7 commit c723505

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

src/SDK/Trace/SpanSuppression/SemanticConventionSuppressionStrategy/SemanticConventionSuppressionStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getSuppressor(string $name, ?string $version, ?string $schemaUrl
5959
foreach ($semanticConvention->samplingAttributes as $attribute) {
6060
$lookup[$semanticConvention->spanKind][$attribute][0] |= 1 << $i;
6161
}
62-
foreach ($lookup[$semanticConvention->spanKind] as $attribute => $_) {
62+
foreach (array_keys($lookup[$semanticConvention->spanKind]) as $attribute) {
6363
if (!$attributes->matches($attribute)) {
6464
$lookup[$semanticConvention->spanKind][$attribute][1] |= 1 << $i;
6565
}

src/SDK/Trace/TracerProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function __construct(
3535
?IdGeneratorInterface $idGenerator = null,
3636
?InstrumentationScopeFactoryInterface $instrumentationScopeFactory = null,
3737
private ?Configurator $configurator = null,
38-
private SpanSuppressionStrategy $spanSuppressionStrategy = new NoopSuppressionStrategy(),
38+
private readonly SpanSuppressionStrategy $spanSuppressionStrategy = new NoopSuppressionStrategy(),
3939
) {
4040
$spanProcessors ??= [];
4141
$spanProcessors = is_array($spanProcessors) ? $spanProcessors : [$spanProcessors];

tests/Unit/Contrib/Otlp/LogsConverterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function test_convert(): void
3636
$this->record->method('getBody')->willReturn('body');
3737

3838
$request = $this->converter->convert([$this->record]);
39-
/** @psalm-suppress InvalidArgument */
39+
/** @psalm-suppress InvalidArgument,PossiblyNullReference */
4040
$row = $request->getResourceLogs()[0]->getScopeLogs()[0]->getLogRecords()[0];
4141
$this->assertSame('body', $row->getBody()->getStringValue());
4242
}
@@ -49,7 +49,7 @@ public function test_convert_with_context(): void
4949
$span->method('getContext')->willReturn($spanContext);
5050
$this->record->method('getSpanContext')->willReturn($spanContext);
5151
$request = $this->converter->convert([$this->record]);
52-
/** @psalm-suppress InvalidArgument */
52+
/** @psalm-suppress InvalidArgument,PossiblyNullReference */
5353
$row = $request->getResourceLogs()[0]->getScopeLogs()[0]->getLogRecords()[0];
5454
$this->assertSame(self::TRACE_ID_BASE16, bin2hex((string) $row->getTraceId()));
5555
$this->assertSame(self::SPAN_ID_BASE16, bin2hex((string) $row->getSpanId()));

tests/Unit/Contrib/Otlp/SpanConverterTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
class SpanConverterTest extends TestCase
3434
{
3535
/**
36-
* @psalm-suppress InvalidArgument
36+
* @psalm-suppress InvalidArgument,PossiblyNullReference
3737
*/
3838
public function test_convert_span_to_payload(): void
3939
{
@@ -85,12 +85,13 @@ public function test_span_context_is_remote_flags(): void
8585
$convertSpanData = static function (SpanData $spanData): ProtoSpan {
8686
$converter = new SpanConverter();
8787

88-
/** @psalm-suppress InvalidArgument */
88+
/** @psalm-suppress InvalidArgument,PossiblyNullReference */
8989
return $converter->convert([$spanData])->getResourceSpans()[0]->getScopeSpans()[0]->getSpans()[0];
9090
};
9191

92+
/** @psalm-suppress InvalidNullableReturnType */
9293
$getLink = static function (ProtoSpan $protoSpan, int $linkIndex): ProtoSpanLink {
93-
/** @psalm-suppress InvalidArgument */
94+
/** @psalm-suppress InvalidArgument,NullableReturnStatement */
9495
return $protoSpan->getLinks()[$linkIndex];
9596
};
9697

@@ -130,6 +131,7 @@ public function test_attribute_are_coerced_correctly($actual, $expected): void
130131
$converter = new SpanConverter();
131132
/** @psalm-suppress InvalidArgument */
132133
$converted = $converter->convert([$span])->getResourceSpans()[0];
134+
/** @psalm-suppress PossiblyNullReference */
133135
$attributes = $converted->getScopeSpans()[0]->getSpans()[0]->getAttributes();
134136

135137
// Check that we can convert all attributes to tags
@@ -308,7 +310,7 @@ public function test_resources_from_multiple_spans_are_not_duplicated(): void
308310
$resource->method('getAttributes')->willReturn($attributes);
309311
$converter = new SpanConverter();
310312
$result = $converter->convert([$span, $span, $span])->getResourceSpans();
311-
/** @psalm-suppress InvalidArgument */
313+
/** @psalm-suppress InvalidArgument,PossiblyNullReference */
312314
$this->assertCount(2, $result[0]->getResource()->getAttributes());
313315
}
314316

@@ -339,7 +341,7 @@ public function test_otlp_no_spans(): void
339341
public function test_span_kind($kind, $expected): void
340342
{
341343
$span = (new SpanData())->setKind($kind);
342-
/** @psalm-suppress InvalidArgument */
344+
/** @psalm-suppress InvalidArgument,PossiblyNullReference */
343345
$row = (new SpanConverter())->convert([$span])->getResourceSpans()[0]->getScopeSpans()[0]->getSpans()[0];
344346
$this->assertSame($expected, $row->getKind());
345347
}
@@ -359,7 +361,7 @@ public static function spanKindProvider(): array
359361
public function test_span_with_error_status(): void
360362
{
361363
$span = (new SpanData())->setStatus(StatusData::error());
362-
/** @psalm-suppress InvalidArgument */
364+
/** @psalm-suppress InvalidArgument,PossiblyNullReference */
363365
$row = (new SpanConverter())->convert([$span])->getResourceSpans()[0]->getScopeSpans()[0]->getSpans()[0];
364366
$this->assertSame(V1\Status\StatusCode::STATUS_CODE_ERROR, $row->getStatus()->getCode());
365367
}

0 commit comments

Comments
 (0)