From bb07aca7a201b95d3974afeff79a5b76fc46b457 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 4 Mar 2024 22:58:09 +1100 Subject: [PATCH] upgrade psalm to v5 (#1246) --- composer.json | 6 +- .../autoload_sdk_with_custom_transport.php | 1 + examples/traces/exporters/otlp_http_json.php | 3 +- psalm.xml.dist | 7 ++ src/API/Baggage/Propagation/Parser.php | 1 + .../Behavior/Internal/LogWriter/Formatter.php | 4 + src/Context/ContextKey.php | 1 + src/Context/ContextStorageScopeInterface.php | 3 + src/Contrib/Grpc/GrpcTransportFactory.php | 1 + src/Contrib/Otlp/ContentTypes.php | 3 + src/SDK/Common/Attribute/Attributes.php | 3 + .../Attribute/AttributesBuilderInterface.php | 3 + .../Common/Attribute/AttributesInterface.php | 3 + .../Common/Configuration/Parser/MapParser.php | 1 + .../Common/Exception/StackTraceFormatter.php | 2 +- src/SDK/Common/Export/Http/PsrTransport.php | 6 ++ src/SDK/Common/Export/Http/PsrUtils.php | 1 + src/SDK/Common/Future/ErrorFuture.php | 3 + src/SDK/Common/Util/functions.php | 5 +- src/SDK/Logs/Exporter/InMemoryExporter.php | 2 +- src/SDK/Metrics/View/CriteriaViewRegistry.php | 3 + .../InstrumentNameCriteria.php | 6 ++ src/SDK/Propagation/PropagatorFactory.php | 2 +- .../Trace/SpanExporter/InMemoryExporter.php | 2 +- src/SDK/Trace/TracerProviderBuilder.php | 2 +- tests/Benchmark/OtlpBench.php | 3 + .../API/Baggage/Propagation/ParserTest.php | 1 + .../Propagator/B3/B3PropagatorTest.php | 75 ++++++++++--------- .../Propagator/B3/B3SinglePropagatorTest.php | 3 + .../CloudTracePropagatorOneWayTest.php | 3 + .../CloudTrace/CloudTracePropagatorTest.php | 3 + .../Jaeger/JaegerPropagatorTest.php | 3 + .../Processor/BatchLogRecordProcessorTest.php | 6 ++ tests/Unit/SDK/Metrics/MeterTest.php | 12 +++ .../MetricFactory/StreamFactoryTest.php | 3 + .../MetricRegistry/MetricRegistryTest.php | 6 ++ .../Metrics/View/CriteriaViewRegistryTest.php | 3 + .../Metrics/View/SelectionCriteriaTest.php | 1 + .../SpanProcessor/BatchSpanProcessorTest.php | 9 +++ .../SpanProcessor/SimpleSpanProcessorTest.php | 3 + 40 files changed, 162 insertions(+), 46 deletions(-) diff --git a/composer.json b/composer.json index 7d8b14697..059819d35 100644 --- a/composer.json +++ b/composer.json @@ -98,11 +98,11 @@ "phpstan/phpstan-mockery": "^1.1", "phpstan/phpstan-phpunit": "^1.3", "phpunit/phpunit": "^9.6", - "psalm/plugin-mockery": "^0.11", + "psalm/plugin-mockery": "^1", "psalm/plugin-phpunit": "^0.18.4", - "psalm/psalm": "^4.30", + "psalm/psalm": "^5", "qossmic/deptrac-shim": "^0.24 || ^1", - "rector/rector": ">=0.15.20", + "rector/rector": "^1", "symfony/http-client": "^5.2", "symfony/yaml": "^6 || ^5" }, diff --git a/examples/autoload_sdk_with_custom_transport.php b/examples/autoload_sdk_with_custom_transport.php index 99f412466..28d742caf 100644 --- a/examples/autoload_sdk_with_custom_transport.php +++ b/examples/autoload_sdk_with_custom_transport.php @@ -21,6 +21,7 @@ * create a transport factory to override the default grpc one (for both traces and metrics): * @psalm-suppress InvalidReturnType * @psalm-suppress InvalidReturnStatement + * @psalm-suppress MissingTemplateParam */ $factory = new class() implements \OpenTelemetry\SDK\Common\Export\TransportFactoryInterface { public function create(string $endpoint, string $contentType, array $headers = [], $compression = null, float $timeout = 10., int $retryDelay = 100, int $maxRetries = 3, ?string $cacert = null, ?string $cert = null, ?string $key = null): \OpenTelemetry\SDK\Common\Export\TransportInterface diff --git a/examples/traces/exporters/otlp_http_json.php b/examples/traces/exporters/otlp_http_json.php index 5ec349384..c89c267a6 100644 --- a/examples/traces/exporters/otlp_http_json.php +++ b/examples/traces/exporters/otlp_http_json.php @@ -6,12 +6,13 @@ require __DIR__ . '/../../../vendor/autoload.php'; +use OpenTelemetry\Contrib\Otlp\ContentTypes; use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory; use OpenTelemetry\Contrib\Otlp\SpanExporter; use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor; use OpenTelemetry\SDK\Trace\TracerProvider; -$transport = (new OtlpHttpTransportFactory())->create('http://collector:4318/v1/traces', 'application/json'); +$transport = (new OtlpHttpTransportFactory())->create('http://collector:4318/v1/traces', ContentTypes::JSON); $exporter = new SpanExporter($transport); echo 'Starting OTLP+json example'; diff --git a/psalm.xml.dist b/psalm.xml.dist index bbcd259c9..b6f04150f 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -2,6 +2,8 @@ @@ -24,5 +26,10 @@ + + + + + diff --git a/src/API/Baggage/Propagation/Parser.php b/src/API/Baggage/Propagation/Parser.php index 2473c8235..34fa2c80c 100644 --- a/src/API/Baggage/Propagation/Parser.php +++ b/src/API/Baggage/Propagation/Parser.php @@ -46,6 +46,7 @@ public function parseInto(BaggageBuilderInterface $baggageBuilder): void $metadata = null; } + /** @psalm-suppress PossiblyUndefinedArrayOffset */ [$key, $value] = explode(self::EQUALS, $keyValue, 2); $key = urldecode($key); diff --git a/src/API/Behavior/Internal/LogWriter/Formatter.php b/src/API/Behavior/Internal/LogWriter/Formatter.php index 2677662b9..ab71faf60 100644 --- a/src/API/Behavior/Internal/LogWriter/Formatter.php +++ b/src/API/Behavior/Internal/LogWriter/Formatter.php @@ -25,6 +25,10 @@ public static function format($level, string $message, array $context): string } else { //get calling location, skipping over trait, formatter etc $caller = debug_backtrace()[3]; + /** + * @psalm-suppress PossiblyNullArgument + * @psalm-suppress PossiblyUndefinedArrayOffset + */ $message = sprintf( 'OpenTelemetry: [%s] %s in %s(%s)', $level, diff --git a/src/Context/ContextKey.php b/src/Context/ContextKey.php index 16ecb49ee..08466e3a8 100644 --- a/src/Context/ContextKey.php +++ b/src/Context/ContextKey.php @@ -6,6 +6,7 @@ /** * @internal + * @psalm-suppress MissingTemplateParam */ final class ContextKey implements ContextKeyInterface { diff --git a/src/Context/ContextStorageScopeInterface.php b/src/Context/ContextStorageScopeInterface.php index 5fe58d6eb..bacc1b0dc 100644 --- a/src/Context/ContextStorageScopeInterface.php +++ b/src/Context/ContextStorageScopeInterface.php @@ -6,6 +6,9 @@ use ArrayAccess; +/** + * @psalm-suppress MissingTemplateParam + */ interface ContextStorageScopeInterface extends ScopeInterface, ArrayAccess { /** diff --git a/src/Contrib/Grpc/GrpcTransportFactory.php b/src/Contrib/Grpc/GrpcTransportFactory.php index d2c9ecf4b..246b0cacb 100644 --- a/src/Contrib/Grpc/GrpcTransportFactory.php +++ b/src/Contrib/Grpc/GrpcTransportFactory.php @@ -29,6 +29,7 @@ final class GrpcTransportFactory implements TransportFactoryInterface * @psalm-return TransportInterface<"application/x-protobuf"> * @psalm-suppress MoreSpecificImplementedParamType * @psalm-suppress ImplementedReturnTypeMismatch + * @psalm-suppress NoValue */ public function create( string $endpoint, diff --git a/src/Contrib/Otlp/ContentTypes.php b/src/Contrib/Otlp/ContentTypes.php index 8ac70d54a..bd7d7d1ce 100644 --- a/src/Contrib/Otlp/ContentTypes.php +++ b/src/Contrib/Otlp/ContentTypes.php @@ -4,6 +4,9 @@ namespace OpenTelemetry\Contrib\Otlp; +/** + * @todo enum (php >= 8.1) + */ interface ContentTypes { public const PROTOBUF = 'application/x-protobuf'; diff --git a/src/SDK/Common/Attribute/Attributes.php b/src/SDK/Common/Attribute/Attributes.php index cebf063fd..c75944040 100644 --- a/src/SDK/Common/Attribute/Attributes.php +++ b/src/SDK/Common/Attribute/Attributes.php @@ -8,6 +8,9 @@ use IteratorAggregate; use Traversable; +/** + * @psalm-suppress MissingTemplateParam + */ final class Attributes implements AttributesInterface, IteratorAggregate { /** diff --git a/src/SDK/Common/Attribute/AttributesBuilderInterface.php b/src/SDK/Common/Attribute/AttributesBuilderInterface.php index 14f41190f..140f2ed04 100644 --- a/src/SDK/Common/Attribute/AttributesBuilderInterface.php +++ b/src/SDK/Common/Attribute/AttributesBuilderInterface.php @@ -6,6 +6,9 @@ use ArrayAccess; +/** + * @psalm-suppress MissingTemplateParam + */ interface AttributesBuilderInterface extends ArrayAccess { public function build(): AttributesInterface; diff --git a/src/SDK/Common/Attribute/AttributesInterface.php b/src/SDK/Common/Attribute/AttributesInterface.php index 1af7dc8d9..c23465a7c 100644 --- a/src/SDK/Common/Attribute/AttributesInterface.php +++ b/src/SDK/Common/Attribute/AttributesInterface.php @@ -7,6 +7,9 @@ use Countable; use Traversable; +/** + * @psalm-suppress MissingTemplateParam + */ interface AttributesInterface extends Traversable, Countable { public function has(string $name): bool; diff --git a/src/SDK/Common/Configuration/Parser/MapParser.php b/src/SDK/Common/Configuration/Parser/MapParser.php index 7e0d44534..e059662bf 100644 --- a/src/SDK/Common/Configuration/Parser/MapParser.php +++ b/src/SDK/Common/Configuration/Parser/MapParser.php @@ -25,6 +25,7 @@ public static function parse($value): array foreach (explode(self::VARIABLE_SEPARATOR, $value) as $pair) { self::validateKeyValuePair($pair); + /** @psalm-suppress PossiblyUndefinedArrayOffset */ [$key, $value] = explode(self::KEY_VALUE_SEPARATOR, $pair, 2); $result[trim($key)] = trim($value); } diff --git a/src/SDK/Common/Exception/StackTraceFormatter.php b/src/SDK/Common/Exception/StackTraceFormatter.php index 8fc7a2104..db490ea1b 100644 --- a/src/SDK/Common/Exception/StackTraceFormatter.php +++ b/src/SDK/Common/Exception/StackTraceFormatter.php @@ -124,8 +124,8 @@ private static function writeNewline(string &$s, int $indent = 0): void /** * @psalm-return Frames - * * @psalm-suppress PossiblyUndefinedArrayOffset + * @psalm-suppress InvalidArrayOffset */ private static function frames(Throwable $e): array { diff --git a/src/SDK/Common/Export/Http/PsrTransport.php b/src/SDK/Common/Export/Http/PsrTransport.php index 99530fcc1..d12acd725 100644 --- a/src/SDK/Common/Export/Http/PsrTransport.php +++ b/src/SDK/Common/Export/Http/PsrTransport.php @@ -53,6 +53,9 @@ public function contentType(): string return $this->contentType; } + /** + * @psalm-suppress ArgumentTypeCoercion + */ public function send(string $payload, ?CancellationInterface $cancellation = null): FutureInterface { if ($this->closed) { @@ -118,6 +121,9 @@ public function send(string $payload, ?CancellationInterface $cancellation = nul return new CompletedFuture($body); } + /** + * @return list + */ private static function parseContentEncoding(ResponseInterface $response): array { $encodings = []; diff --git a/src/SDK/Common/Export/Http/PsrUtils.php b/src/SDK/Common/Export/Http/PsrUtils.php index 7cc020818..33cd0c7e4 100644 --- a/src/SDK/Common/Export/Http/PsrUtils.php +++ b/src/SDK/Common/Export/Http/PsrUtils.php @@ -87,6 +87,7 @@ public static function encode(string $value, array $encodings, ?array &$appliedE /** * @param list $encodings + * @psalm-suppress InvalidArrayOffset */ public static function decode(string $value, array $encodings): string { diff --git a/src/SDK/Common/Future/ErrorFuture.php b/src/SDK/Common/Future/ErrorFuture.php index 253ca803e..061cde54f 100644 --- a/src/SDK/Common/Future/ErrorFuture.php +++ b/src/SDK/Common/Future/ErrorFuture.php @@ -7,6 +7,9 @@ use Closure; use Throwable; +/** + * @psalm-suppress MissingTemplateParam + */ final class ErrorFuture implements FutureInterface { public function __construct(private Throwable $throwable) diff --git a/src/SDK/Common/Util/functions.php b/src/SDK/Common/Util/functions.php index dcda96241..a51551e88 100644 --- a/src/SDK/Common/Util/functions.php +++ b/src/SDK/Common/Util/functions.php @@ -40,11 +40,14 @@ function weaken(Closure $closure, ?object &$target = null): Closure static $placeholder; $placeholder ??= new stdClass(); + /** @psalm-suppress PossiblyNullReference */ $closure = $closure->bindTo($placeholder); $ref = WeakReference::create($target); - /** @psalm-suppress PossiblyInvalidFunctionCall */ + /** + * @psalm-suppress all + */ return $scope && $target::class === $scope->name && !$scope->isInternal() ? static fn (...$args) => ($obj = $ref->get()) ? $closure->call($obj, ...$args) : null : static fn (...$args) => ($obj = $ref->get()) ? $closure->bindTo($obj)(...$args) : null; diff --git a/src/SDK/Logs/Exporter/InMemoryExporter.php b/src/SDK/Logs/Exporter/InMemoryExporter.php index dca0531f3..871eb48a2 100644 --- a/src/SDK/Logs/Exporter/InMemoryExporter.php +++ b/src/SDK/Logs/Exporter/InMemoryExporter.php @@ -25,7 +25,7 @@ public function __construct(?ArrayObject $storage = null) public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface { foreach ($batch as $record) { - $this->storage[] = $record; + $this->storage->append($record); } return new CompletedFuture(true); diff --git a/src/SDK/Metrics/View/CriteriaViewRegistry.php b/src/SDK/Metrics/View/CriteriaViewRegistry.php index f387abf9c..254c87286 100644 --- a/src/SDK/Metrics/View/CriteriaViewRegistry.php +++ b/src/SDK/Metrics/View/CriteriaViewRegistry.php @@ -22,6 +22,9 @@ public function register(SelectionCriteriaInterface $criteria, ViewTemplate $vie $this->views[] = $view; } + /** + * @todo is null the best return type here? what about empty array or exception? + */ public function find(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): ?iterable { $views = $this->generateViews($instrument, $instrumentationScope); diff --git a/src/SDK/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php b/src/SDK/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php index ed6034755..dbba6a068 100644 --- a/src/SDK/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php +++ b/src/SDK/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php @@ -16,11 +16,17 @@ final class InstrumentNameCriteria implements SelectionCriteriaInterface { private string $pattern; + /** + * @param non-empty-string $name + */ public function __construct(string $name) { $this->pattern = sprintf('/^%s$/', strtr(preg_quote($name, '/'), ['\\?' => '.', '\\*' => '.*'])); } + /** + * @psalm-suppress ArgumentTypeCoercion + */ public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool { return (bool) preg_match($this->pattern, $instrument->name); diff --git a/src/SDK/Propagation/PropagatorFactory.php b/src/SDK/Propagation/PropagatorFactory.php index 4b3970420..66160aad3 100644 --- a/src/SDK/Propagation/PropagatorFactory.php +++ b/src/SDK/Propagation/PropagatorFactory.php @@ -28,7 +28,7 @@ public function create(): TextMapPropagatorInterface } /** - * @return array + * @return list */ private function buildPropagators(array $names): array { diff --git a/src/SDK/Trace/SpanExporter/InMemoryExporter.php b/src/SDK/Trace/SpanExporter/InMemoryExporter.php index ebb022595..04d2becb9 100644 --- a/src/SDK/Trace/SpanExporter/InMemoryExporter.php +++ b/src/SDK/Trace/SpanExporter/InMemoryExporter.php @@ -22,7 +22,7 @@ public function __construct(?ArrayObject $storage = null) protected function doExport(iterable $spans): bool { foreach ($spans as $span) { - $this->storage[] = $span; + $this->storage->append($span); } return true; diff --git a/src/SDK/Trace/TracerProviderBuilder.php b/src/SDK/Trace/TracerProviderBuilder.php index 8dcfdc700..5a1cb4ae5 100644 --- a/src/SDK/Trace/TracerProviderBuilder.php +++ b/src/SDK/Trace/TracerProviderBuilder.php @@ -8,7 +8,7 @@ class TracerProviderBuilder { - // @var array + /** @var list */ private ?array $spanProcessors = []; private ?ResourceInfo $resource = null; private ?SamplerInterface $sampler = null; diff --git a/tests/Benchmark/OtlpBench.php b/tests/Benchmark/OtlpBench.php index 502a0619b..5250ee34b 100644 --- a/tests/Benchmark/OtlpBench.php +++ b/tests/Benchmark/OtlpBench.php @@ -51,6 +51,9 @@ public function setUpNoExporter(): void $this->tracer = $provider->getTracer('io.opentelemetry.contrib.php'); } + /** + * @psalm-suppress MissingTemplateParam + */ private function createTransport(string $contentType): TransportInterface { return new class($contentType) implements TransportInterface { diff --git a/tests/Unit/API/Baggage/Propagation/ParserTest.php b/tests/Unit/API/Baggage/Propagation/ParserTest.php index d4c3fb485..956aa173a 100644 --- a/tests/Unit/API/Baggage/Propagation/ParserTest.php +++ b/tests/Unit/API/Baggage/Propagation/ParserTest.php @@ -100,6 +100,7 @@ public static function invalidHeaderProvider(): array 'empty key' => ['=value'], 'key with invalid char' => ['@foo=bar'], 'value with invalid char' => ['foo="bar"'], + 'missing value' => ['key1='], ]; } } diff --git a/tests/Unit/Extension/Propagator/B3/B3PropagatorTest.php b/tests/Unit/Extension/Propagator/B3/B3PropagatorTest.php index 6b67933d3..e1d7f3462 100644 --- a/tests/Unit/Extension/Propagator/B3/B3PropagatorTest.php +++ b/tests/Unit/Extension/Propagator/B3/B3PropagatorTest.php @@ -28,18 +28,21 @@ class B3PropagatorTest extends TestCase private const IS_SAMPLED = '1'; private const IS_NOT_SAMPLED = '0'; - private $B3; - private $TRACE_ID; - private $SPAN_ID; - private $SAMPLED; + private string $b3; + private string $traceId; + private string $spanId; + private string $sampled; + /** + * @psalm-suppress PossiblyUndefinedArrayOffset + */ public function setUp(): void { - [$this->B3] = B3SinglePropagator::getInstance()->fields(); + [$this->b3] = B3SinglePropagator::getInstance()->fields(); $b3MultiFields = B3MultiPropagator::getInstance()->fields(); - $this->TRACE_ID = $b3MultiFields[0]; - $this->SPAN_ID = $b3MultiFields[1]; - $this->SAMPLED = $b3MultiFields[3]; + $this->traceId = $b3MultiFields[0]; + $this->spanId = $b3MultiFields[1]; + $this->sampled = $b3MultiFields[3]; } public function test_b3multi_fields(): void @@ -75,9 +78,9 @@ public function test_b3multi_inject(): void $this->assertSame( [ - $this->TRACE_ID => self::B3_TRACE_ID, - $this->SPAN_ID => self::B3_SPAN_ID, - $this->SAMPLED => self::IS_SAMPLED, + $this->traceId => self::B3_TRACE_ID, + $this->spanId => self::B3_SPAN_ID, + $this->sampled => self::IS_SAMPLED, ], $carrier ); @@ -97,7 +100,7 @@ public function test_b3single_inject(): void ); $this->assertSame( - [$this->B3 => self::B3_SINGLE_HEADER_SAMPLED], + [$this->b3 => self::B3_SINGLE_HEADER_SAMPLED], $carrier ); } @@ -105,7 +108,7 @@ public function test_b3single_inject(): void public function test_extract_only_b3single_sampled_context_with_b3single_instance(): void { $carrier = [ - $this->B3 => self::B3_SINGLE_HEADER_SAMPLED, + $this->b3 => self::B3_SINGLE_HEADER_SAMPLED, ]; $propagator = B3Propagator::getB3SingleHeaderInstance(); @@ -123,7 +126,7 @@ public function test_extract_only_b3single_sampled_context_with_b3single_instanc public function test_extract_only_b3single_sampled_context_with_b3multi_instance(): void { $carrier = [ - $this->B3 => self::B3_SINGLE_HEADER_SAMPLED, + $this->b3 => self::B3_SINGLE_HEADER_SAMPLED, ]; $propagator = B3Propagator::getB3MultiHeaderInstance(); @@ -141,9 +144,9 @@ public function test_extract_only_b3single_sampled_context_with_b3multi_instance public function test_extract_only_b3multi_sampled_context_with_b3single_instance(): void { $carrier = [ - $this->TRACE_ID => self::B3_TRACE_ID, - $this->SPAN_ID => self::B3_SPAN_ID, - $this->SAMPLED => self::IS_SAMPLED, + $this->traceId => self::B3_TRACE_ID, + $this->spanId => self::B3_SPAN_ID, + $this->sampled => self::IS_SAMPLED, ]; $propagator = B3Propagator::getB3SingleHeaderInstance(); @@ -162,9 +165,9 @@ public function test_extract_only_b3multi_sampled_context_with_b3single_instance public function test_extract_only_b3multi_sampled_context_with_b3multi_instance(string $traceId, string $expected): void { $carrier = [ - $this->TRACE_ID => $traceId, - $this->SPAN_ID => self::B3_SPAN_ID, - $this->SAMPLED => self::IS_SAMPLED, + $this->traceId => $traceId, + $this->spanId => self::B3_SPAN_ID, + $this->sampled => self::IS_SAMPLED, ]; $propagator = B3Propagator::getB3MultiHeaderInstance(); @@ -210,10 +213,10 @@ public static function validTraceIdProvider(): array public function test_extract_both_sampled_context_with_b3single_instance(): void { $carrier = [ - $this->TRACE_ID => self::B3_TRACE_ID, - $this->SPAN_ID => self::B3_SPAN_ID, - $this->SAMPLED => self::IS_NOT_SAMPLED, - $this->B3 => self::B3_SINGLE_HEADER_SAMPLED, + $this->traceId => self::B3_TRACE_ID, + $this->spanId => self::B3_SPAN_ID, + $this->sampled => self::IS_NOT_SAMPLED, + $this->b3 => self::B3_SINGLE_HEADER_SAMPLED, ]; $propagator = B3Propagator::getB3SingleHeaderInstance(); @@ -229,10 +232,10 @@ public function test_extract_both_sampled_context_with_b3single_instance(): void public function test_extract_both_sampled_context_with_b3multi_instance(): void { $carrier = [ - $this->TRACE_ID => self::B3_TRACE_ID, - $this->SPAN_ID => self::B3_SPAN_ID, - $this->SAMPLED => self::IS_NOT_SAMPLED, - $this->B3 => self::B3_SINGLE_HEADER_SAMPLED, + $this->traceId => self::B3_TRACE_ID, + $this->spanId => self::B3_SPAN_ID, + $this->sampled => self::IS_NOT_SAMPLED, + $this->b3 => self::B3_SINGLE_HEADER_SAMPLED, ]; $propagator = B3Propagator::getB3MultiHeaderInstance(); @@ -251,10 +254,10 @@ public function test_extract_both_sampled_context_with_b3multi_instance(): void public function test_extract_b3_single_invalid_and_b3_multi_valid_context_with_b3single_instance($headerValue): void { $carrier = [ - $this->TRACE_ID => self::B3_TRACE_ID, - $this->SPAN_ID => self::B3_SPAN_ID, - $this->SAMPLED => self::IS_NOT_SAMPLED, - $this->B3 => $headerValue, + $this->traceId => self::B3_TRACE_ID, + $this->spanId => self::B3_SPAN_ID, + $this->sampled => self::IS_NOT_SAMPLED, + $this->b3 => $headerValue, ]; $propagator = B3Propagator::getB3SingleHeaderInstance(); @@ -273,10 +276,10 @@ public function test_extract_b3_single_invalid_and_b3_multi_valid_context_with_b public function test_extract_b3_single_invalid_and_b3_multi_valid_context_with_b3multi_instance($headerValue): void { $carrier = [ - $this->TRACE_ID => self::B3_TRACE_ID, - $this->SPAN_ID => self::B3_SPAN_ID, - $this->SAMPLED => self::IS_NOT_SAMPLED, - $this->B3 => $headerValue, + $this->traceId => self::B3_TRACE_ID, + $this->spanId => self::B3_SPAN_ID, + $this->sampled => self::IS_NOT_SAMPLED, + $this->b3 => $headerValue, ]; $propagator = B3Propagator::getB3MultiHeaderInstance(); diff --git a/tests/Unit/Extension/Propagator/B3/B3SinglePropagatorTest.php b/tests/Unit/Extension/Propagator/B3/B3SinglePropagatorTest.php index 336d86e6f..ed9669b1f 100644 --- a/tests/Unit/Extension/Propagator/B3/B3SinglePropagatorTest.php +++ b/tests/Unit/Extension/Propagator/B3/B3SinglePropagatorTest.php @@ -32,6 +32,9 @@ class B3SinglePropagatorTest extends TestCase private B3SinglePropagator $b3SinglePropagator; + /** + * @psalm-suppress PossiblyUndefinedArrayOffset + */ protected function setUp(): void { $this->b3SinglePropagator = B3SinglePropagator::getInstance(); diff --git a/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorOneWayTest.php b/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorOneWayTest.php index 82ab47582..65b72558e 100644 --- a/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorOneWayTest.php +++ b/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorOneWayTest.php @@ -30,6 +30,9 @@ class CloudTracePropagatorOneWayTest extends TestCase private TextMapPropagatorInterface $cloudTracePropagator; + /** + * @psalm-suppress PossiblyUndefinedArrayOffset + */ protected function setUp(): void { $this->cloudTracePropagator = CloudTracePropagator::getOneWayInstance(); diff --git a/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorTest.php b/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorTest.php index ac585dc9d..7a6317f15 100644 --- a/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorTest.php +++ b/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorTest.php @@ -30,6 +30,9 @@ class CloudTracePropagatorTest extends TestCase private TextMapPropagatorInterface $cloudTracePropagator; + /** + * @psalm-suppress PossiblyUndefinedArrayOffset + */ protected function setUp(): void { $this->cloudTracePropagator = CloudTracePropagator::getInstance(); diff --git a/tests/Unit/Extension/Propagator/Jaeger/JaegerPropagatorTest.php b/tests/Unit/Extension/Propagator/Jaeger/JaegerPropagatorTest.php index 54ff57dce..a8d8e57f2 100644 --- a/tests/Unit/Extension/Propagator/Jaeger/JaegerPropagatorTest.php +++ b/tests/Unit/Extension/Propagator/Jaeger/JaegerPropagatorTest.php @@ -48,6 +48,9 @@ private function generateTraceIdHeaderValue( ); } + /** + * @psalm-suppress PossiblyUndefinedArrayOffset + */ protected function setUp(): void { $this->propagator = JaegerPropagator::getInstance(); diff --git a/tests/Unit/SDK/Logs/Processor/BatchLogRecordProcessorTest.php b/tests/Unit/SDK/Logs/Processor/BatchLogRecordProcessorTest.php index 075847be3..44ad41eb4 100644 --- a/tests/Unit/SDK/Logs/Processor/BatchLogRecordProcessorTest.php +++ b/tests/Unit/SDK/Logs/Processor/BatchLogRecordProcessorTest.php @@ -270,6 +270,10 @@ function (array $records) { $processor->forceFlush(); } + /** + * @psalm-suppress UndefinedVariable + * @psalm-suppress RedundantCondition + */ public function test_queue_size_exceeded_drops_spans(): void { $exporter = $this->createMock(LogRecordExporterInterface::class); @@ -357,6 +361,7 @@ public function test_throwing_exporter_flush(): void public function test_throwing_exporter_flush_cannot_rethrow_in_original_caller_logs_error(): void { + $processor = null; $exporter = $this->createMock(LogRecordExporterInterface::class); $exporter->method('forceFlush')->willReturnCallback(function () use (&$processor) { /** @var LogRecordProcessorInterface $processor */ @@ -380,6 +385,7 @@ public function test_throwing_exporter_flush_cannot_rethrow_in_original_caller_l public function test_throwing_exporter_flush_rethrows_in_original_caller(): void { $exporter = $this->createMock(LogRecordExporterInterface::class); + $processor = null; $exporter->method('forceFlush')->willReturnCallback(function () use (&$processor) { /** @var LogRecordProcessorInterface $processor */ $record = $this->createMock(ReadWriteLogRecord::class); diff --git a/tests/Unit/SDK/Metrics/MeterTest.php b/tests/Unit/SDK/Metrics/MeterTest.php index c6cb66f37..531df2e93 100644 --- a/tests/Unit/SDK/Metrics/MeterTest.php +++ b/tests/Unit/SDK/Metrics/MeterTest.php @@ -261,6 +261,10 @@ public function test_releases_observer_on_stale(): void $meter->createObservableCounter('name', 'unit', 'description'); } + /** + * @psalm-suppress InvalidOperand + * @psalm-suppress PossiblyUndefinedArrayOffset + */ public function test_uses_view_registry_to_create_views(): void { $aggregation = $this->createMock(AggregationInterface::class); @@ -289,6 +293,10 @@ public function test_uses_view_registry_to_create_views(): void $meter->createCounter('name'); } + /** + * @psalm-suppress InvalidOperand + * @psalm-suppress PossiblyUndefinedArrayOffset + */ public function test_uses_default_aggregation_if_view_aggregation_null(): void { $aggregation = $this->createMock(AggregationInterface::class); @@ -316,6 +324,10 @@ public function test_uses_default_aggregation_if_view_aggregation_null(): void $meter->createCounter('name'); } + /** + * @psalm-suppress InvalidOperand + * @psalm-suppress PossiblyUndefinedArrayOffset + */ public function test_uses_default_view_if_null_views_returned(): void { $aggregation = $this->createMock(AggregationInterface::class); diff --git a/tests/Unit/SDK/Metrics/MetricFactory/StreamFactoryTest.php b/tests/Unit/SDK/Metrics/MetricFactory/StreamFactoryTest.php index e627d2051..bcac1f0fb 100644 --- a/tests/Unit/SDK/Metrics/MetricFactory/StreamFactoryTest.php +++ b/tests/Unit/SDK/Metrics/MetricFactory/StreamFactoryTest.php @@ -168,6 +168,9 @@ final class CollectingSourceRegistry implements MetricSourceRegistryInterface */ public array $sources = []; + /** + * @psalm-suppress InvalidPropertyAssignmentValue + */ public function add(MetricSourceProviderInterface $provider, MetricMetadataInterface $metadata, StalenessHandlerInterface $stalenessHandler): void { $this->sources[] = func_get_args(); diff --git a/tests/Unit/SDK/Metrics/MetricRegistry/MetricRegistryTest.php b/tests/Unit/SDK/Metrics/MetricRegistry/MetricRegistryTest.php index 422762e77..e3fb5404e 100644 --- a/tests/Unit/SDK/Metrics/MetricRegistry/MetricRegistryTest.php +++ b/tests/Unit/SDK/Metrics/MetricRegistry/MetricRegistryTest.php @@ -62,6 +62,9 @@ public function test_collect_and_push_callback_value(): void ], Temporality::CUMULATIVE, true), $stream->collect($reader)); } + /** + * @psalm-suppress RedundantFunctionCall + */ public function test_collect_and_push_invokes_requested_callback_only_once(): void { $this->expectOutputString('0'); @@ -79,6 +82,9 @@ public function test_collect_and_push_invokes_requested_callback_only_once(): vo $registry->collectAndPush([$streamId0, $streamId1]); } + /** + * @psalm-suppress RedundantFunctionCall + */ public function test_collect_and_push_invokes_only_requested_callbacks(): void { $this->expectOutputString('0011'); diff --git a/tests/Unit/SDK/Metrics/View/CriteriaViewRegistryTest.php b/tests/Unit/SDK/Metrics/View/CriteriaViewRegistryTest.php index 4ba83804d..276b67566 100644 --- a/tests/Unit/SDK/Metrics/View/CriteriaViewRegistryTest.php +++ b/tests/Unit/SDK/Metrics/View/CriteriaViewRegistryTest.php @@ -28,6 +28,9 @@ public function test_empty_registry_returns_null(): void )); } + /** + * @psalm-suppress InvalidOperand + */ public function test_registry_returns_matching_entry(): void { $views = new CriteriaViewRegistry(); diff --git a/tests/Unit/SDK/Metrics/View/SelectionCriteriaTest.php b/tests/Unit/SDK/Metrics/View/SelectionCriteriaTest.php index 734086b8b..f17a292dc 100644 --- a/tests/Unit/SDK/Metrics/View/SelectionCriteriaTest.php +++ b/tests/Unit/SDK/Metrics/View/SelectionCriteriaTest.php @@ -68,6 +68,7 @@ public function test_instrument_scope_schema_url_criteria(): void } /** + * @param non-empty-string $pattern * @covers \OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentNameCriteria * @dataProvider instrumentNameProvider */ diff --git a/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorTest.php b/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorTest.php index 4aef9f111..9e0dc0fc4 100644 --- a/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorTest.php +++ b/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorTest.php @@ -271,6 +271,9 @@ function (array $spans) use ($sampledSpan) { $batchProcessor->forceFlush(); } + /** + * @psalm-suppress UndefinedVariable + */ public function test_force_flush_ended_spans(): void { $batchSize = 3; @@ -311,6 +314,10 @@ function (array $spans) { $processor->forceFlush(); } + /** + * @psalm-suppress UndefinedVariable + * @psalm-suppress RedundantCondition + */ public function test_queue_size_exceeded_drops_spans(): void { $exporter = $this->createMock(SpanExporterInterface::class); @@ -405,6 +412,7 @@ public function test_throwing_exporter_flush(): void public function test_throwing_exporter_flush_cannot_rethrow_in_original_caller_logs_error(): void { + $processor = null; $exporter = $this->createMock(SpanExporterInterface::class); $exporter->method('forceFlush')->willReturnCallback(function () use (&$processor) { /** @var SpanProcessorInterface $processor */ @@ -429,6 +437,7 @@ public function test_throwing_exporter_flush_cannot_rethrow_in_original_caller_l public function test_throwing_exporter_flush_rethrows_in_original_caller(): void { + $processor = null; $exporter = $this->createMock(SpanExporterInterface::class); $exporter->method('forceFlush')->willReturnCallback(function () use (&$processor) { /** @var SpanProcessorInterface $processor */ diff --git a/tests/Unit/SDK/Trace/SpanProcessor/SimpleSpanProcessorTest.php b/tests/Unit/SDK/Trace/SpanProcessor/SimpleSpanProcessorTest.php index 33ae2c1ea..4442139f6 100644 --- a/tests/Unit/SDK/Trace/SpanProcessor/SimpleSpanProcessorTest.php +++ b/tests/Unit/SDK/Trace/SpanProcessor/SimpleSpanProcessorTest.php @@ -100,6 +100,9 @@ public function test_on_end_non_sampled_span(): void $this->simpleSpanProcessor->onEnd($this->readableSpan); } + /** + * @psalm-suppress UndefinedVariable + */ public function test_does_not_trigger_concurrent_export(): void { $spanData = new SpanData();