Skip to content

Commit 5ed1ec0

Browse files
authored
fixing psalm+phpstan protobuf complaints (#1636)
1 parent 5451d57 commit 5ed1ec0

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

phpstan.neon.dist

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,8 @@ parameters:
5050
-
5151
message: "#.*return with type T is not subtype.*#"
5252
paths:
53-
- src/SDK/Common/InstrumentationScope
53+
- src/SDK/Common/InstrumentationScope
54+
-
55+
message: "#.*expects Google\\\\Protobuf\\\\RepeatedField.*#"
56+
paths:
57+
- src/Contrib/Otlp

psalm.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
<referencedFunction name="OpenTelemetry\Instrumentation\hook"/>
3333
</errorLevel>
3434
</UndefinedFunction>
35+
<UndefinedMethod>
36+
<errorLevel type="suppress">
37+
<referencedMethod name="Google\Protobuf\Internal\RepeatedField::offsetGet"/>
38+
<referencedMethod name="Google\Protobuf\Internal\RepeatedField::offsetSet"/>
39+
</errorLevel>
40+
</UndefinedMethod>
3541
<ArgumentTypeCoercion>
3642
<errorLevel type="suppress">
3743
<directory name="./examples"/>

tests/Unit/Contrib/Otlp/MetricConverterTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,15 @@ public function test_gauge_exemplars_are_converted(): void
178178
);
179179
}
180180

181+
/**
182+
* @psalm-suppress InvalidArgument
183+
*/
181184
public function test_multiple_resources_result_in_multiple_resource_metrics(): void
182185
{
183186
$resourceA = ResourceInfo::create(Attributes::create(['foo' => 'bar']));
184187
$resourceB = ResourceInfo::create(Attributes::create(['foo' => 'baz']));
185188
$this->assertCount(
186189
2,
187-
/** @phpstan-ignore-next-line */
188190
(new MetricConverter())->convert([
189191
new Metric(
190192
$this->createMock(InstrumentationScopeInterface::class),

tests/Unit/Contrib/Otlp/SpanConverterTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#[CoversClass(SpanConverter::class)]
3333
class SpanConverterTest extends TestCase
3434
{
35+
/**
36+
* @psalm-suppress InvalidArgument
37+
*/
3538
public function test_convert_span_to_payload(): void
3639
{
3740
$context = SpanContext::getInvalid();
@@ -62,7 +65,6 @@ public function test_convert_span_to_payload(): void
6265
$this->assertSame($context->getTraceId(), bin2hex($link->getTraceId()));
6366
$this->assertSame($context->getSpanId(), bin2hex($link->getSpanId()));
6467
$this->assertSame(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, $link->getFlags());
65-
/** @phpstan-ignore-next-line */
6668
$this->assertCount(1, $link->getAttributes());
6769
}
6870

@@ -310,6 +312,9 @@ public function test_resources_from_multiple_spans_are_not_duplicated(): void
310312
$this->assertCount(2, $result[0]->getResource()->getAttributes());
311313
}
312314

315+
/**
316+
* @psalm-suppress InvalidArgument
317+
*/
313318
public function test_multiple_resources_result_in_multiple_resource_spans(): void
314319
{
315320
$resourceA = ResourceInfo::create(Attributes::create(['foo' => 'bar']));
@@ -319,13 +324,14 @@ public function test_multiple_resources_result_in_multiple_resource_spans(): voi
319324
(new SpanData())->setResource($resourceA),
320325
(new SpanData())->setResource($resourceB),
321326
])->getResourceSpans();
322-
/** @phpstan-ignore-next-line */
323327
$this->assertCount(2, $result);
324328
}
325329

330+
/**
331+
* @psalm-suppress InvalidArgument
332+
*/
326333
public function test_otlp_no_spans(): void
327334
{
328-
/** @phpstan-ignore-next-line */
329335
$this->assertCount(0, (new SpanConverter())->convert([])->getResourceSpans());
330336
}
331337

0 commit comments

Comments
 (0)