fixing psalm+phpstan protobuf complaints (#1636)

This commit is contained in:
Brett McBride 2025-06-16 21:11:54 +10:00 committed by GitHub
parent 5451d57dbf
commit 5ed1ec09db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 5 deletions

View File

@ -50,4 +50,8 @@ parameters:
-
message: "#.*return with type T is not subtype.*#"
paths:
- src/SDK/Common/InstrumentationScope
- src/SDK/Common/InstrumentationScope
-
message: "#.*expects Google\\\\Protobuf\\\\RepeatedField.*#"
paths:
- src/Contrib/Otlp

View File

@ -32,6 +32,12 @@
<referencedFunction name="OpenTelemetry\Instrumentation\hook"/>
</errorLevel>
</UndefinedFunction>
<UndefinedMethod>
<errorLevel type="suppress">
<referencedMethod name="Google\Protobuf\Internal\RepeatedField::offsetGet"/>
<referencedMethod name="Google\Protobuf\Internal\RepeatedField::offsetSet"/>
</errorLevel>
</UndefinedMethod>
<ArgumentTypeCoercion>
<errorLevel type="suppress">
<directory name="./examples"/>

View File

@ -178,13 +178,15 @@ final class MetricConverterTest extends TestCase
);
}
/**
* @psalm-suppress InvalidArgument
*/
public function test_multiple_resources_result_in_multiple_resource_metrics(): void
{
$resourceA = ResourceInfo::create(Attributes::create(['foo' => 'bar']));
$resourceB = ResourceInfo::create(Attributes::create(['foo' => 'baz']));
$this->assertCount(
2,
/** @phpstan-ignore-next-line */
(new MetricConverter())->convert([
new Metric(
$this->createMock(InstrumentationScopeInterface::class),

View File

@ -32,6 +32,9 @@ use PHPUnit\Framework\TestCase;
#[CoversClass(SpanConverter::class)]
class SpanConverterTest extends TestCase
{
/**
* @psalm-suppress InvalidArgument
*/
public function test_convert_span_to_payload(): void
{
$context = SpanContext::getInvalid();
@ -62,7 +65,6 @@ class SpanConverterTest extends TestCase
$this->assertSame($context->getTraceId(), bin2hex($link->getTraceId()));
$this->assertSame($context->getSpanId(), bin2hex($link->getSpanId()));
$this->assertSame(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, $link->getFlags());
/** @phpstan-ignore-next-line */
$this->assertCount(1, $link->getAttributes());
}
@ -310,6 +312,9 @@ class SpanConverterTest extends TestCase
$this->assertCount(2, $result[0]->getResource()->getAttributes());
}
/**
* @psalm-suppress InvalidArgument
*/
public function test_multiple_resources_result_in_multiple_resource_spans(): void
{
$resourceA = ResourceInfo::create(Attributes::create(['foo' => 'bar']));
@ -319,13 +324,14 @@ class SpanConverterTest extends TestCase
(new SpanData())->setResource($resourceA),
(new SpanData())->setResource($resourceB),
])->getResourceSpans();
/** @phpstan-ignore-next-line */
$this->assertCount(2, $result);
}
/**
* @psalm-suppress InvalidArgument
*/
public function test_otlp_no_spans(): void
{
/** @phpstan-ignore-next-line */
$this->assertCount(0, (new SpanConverter())->convert([])->getResourceSpans());
}