From 4cb04999d986f87749073d2b3069685fbb22f223 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 15 Mar 2024 10:14:21 +1100 Subject: [PATCH] drop php 8.0 support (#1256) * bump php to 8.1, apply rector * readonly and typehints * suppress a dodgy readonly property conversion * remove some redundant readonly phpdocs * dont run workflows against 8.0 * more readonly and typehints * phpdoc reformat * typehints * remove php81 polyfill * revert a rector BC breaking change, and disable that rector for ParentBased --- .github/workflows/php.yml | 4 +- .phan/config.php | 2 +- composer.json | 4 +- rector.php | 21 +++-- src/API/Baggage/Baggage.php | 2 +- src/API/Baggage/Entry.php | 4 +- src/API/Baggage/Metadata.php | 2 +- .../Baggage/Propagation/BaggagePropagator.php | 2 +- src/API/Baggage/Propagation/Parser.php | 3 +- .../Internal/LogWriter/Psr3LogWriter.php | 2 +- src/API/Globals.php | 8 +- .../Instrumentation/CachedInstrumentation.php | 8 +- src/API/Logs/EventLogger.php | 4 +- src/API/Trace/NonRecordingSpan.php | 2 +- src/API/Trace/NoopSpanBuilder.php | 2 +- src/API/Trace/SpanContext.php | 8 +- src/API/Trace/TraceState.php | 4 +- src/API/composer.json | 3 +- src/Context/Context.php | 15 +--- src/Context/ContextKey.php | 2 +- src/Context/ContextStorage.php | 6 +- src/Context/DebugScope.php | 8 +- .../ExecutionContextAwareInterface.php | 15 +--- src/Context/FiberBoundContextStorage.php | 11 +-- .../Propagation/MultiTextMapPropagator.php | 10 +-- ...nitizeCombinedHeadersPropagationGetter.php | 2 +- src/Context/composer.json | 3 +- src/Contrib/Grpc/GrpcTransport.php | 6 +- src/Contrib/Grpc/composer.json | 2 +- src/Contrib/Otlp/HttpEndpointResolver.php | 2 +- src/Contrib/Otlp/LogsConverter.php | 2 +- src/Contrib/Otlp/LogsExporterFactory.php | 2 +- src/Contrib/Otlp/MetricConverter.php | 2 +- src/Contrib/Otlp/MetricExporter.php | 6 +- src/Contrib/Otlp/MetricExporterFactory.php | 2 +- src/Contrib/Otlp/ProtobufSerializer.php | 4 +- src/Contrib/Otlp/SpanConverter.php | 2 +- src/Contrib/Otlp/composer.json | 2 +- src/Contrib/Zipkin/Exporter.php | 2 +- src/Contrib/Zipkin/SpanConverter.php | 2 +- src/Contrib/Zipkin/composer.json | 2 +- src/Contrib/composer.json | 3 +- src/Extension/Propagator/B3/B3Propagator.php | 2 +- .../Propagator/B3/B3SinglePropagator.php | 6 +- src/Extension/Propagator/B3/composer.json | 2 +- .../CloudTrace/CloudTraceFormatter.php | 2 +- .../CloudTrace/CloudTracePropagator.php | 2 +- .../Propagator/CloudTrace/composer.json | 2 +- src/Extension/Propagator/Jaeger/composer.json | 2 +- .../HttpDiscovery/DependencyResolver.php | 6 +- src/SDK/Common/Attribute/Attributes.php | 4 +- .../Common/Attribute/AttributesBuilder.php | 13 +-- .../Common/Attribute/AttributesFactory.php | 6 +- .../Attribute/FilteredAttributesBuilder.php | 2 +- .../Attribute/FilteredAttributesFactory.php | 4 +- .../Common/Configuration/Parser/MapParser.php | 4 +- .../Resolver/CompositeResolver.php | 2 +- .../Configuration/Resolver/PhpIniResolver.php | 5 +- src/SDK/Common/Export/Http/PsrTransport.php | 18 ++-- .../Export/Http/PsrTransportFactory.php | 6 +- src/SDK/Common/Export/Http/PsrUtils.php | 4 +- .../Common/Export/Stream/StreamTransport.php | 2 +- src/SDK/Common/Future/ErrorFuture.php | 4 +- .../Http/Psr/Message/MessageFactory.php | 6 +- .../Instrumentation/InstrumentationScope.php | 8 +- .../InstrumentationScopeFactory.php | 2 +- src/SDK/Common/Time/StopWatch.php | 2 +- src/SDK/Common/Time/StopWatchFactory.php | 4 +- src/SDK/Logs/Exporter/ConsoleExporter.php | 2 +- src/SDK/Logs/Exporter/InMemoryExporter.php | 5 +- src/SDK/Logs/LogRecordLimits.php | 2 +- src/SDK/Logs/Logger.php | 4 +- src/SDK/Logs/LoggerProvider.php | 4 +- src/SDK/Logs/LoggerProviderBuilder.php | 4 +- src/SDK/Logs/LoggerSharedState.php | 6 +- .../Processor/BatchLogRecordProcessor.php | 6 +- .../Processor/MultiLogRecordProcessor.php | 2 +- .../Processor/SimpleLogRecordProcessor.php | 2 +- src/SDK/Logs/ReadableLogRecord.php | 4 +- src/SDK/Logs/SimplePsrFileLogger.php | 6 +- .../ExplicitBucketHistogramAggregation.php | 17 +--- .../Metrics/Aggregation/SumAggregation.php | 2 +- .../FilteredAttributeProcessor.php | 2 +- src/SDK/Metrics/Data/Exemplar.php | 17 ++-- src/SDK/Metrics/Data/Gauge.php | 3 +- src/SDK/Metrics/Data/Histogram.php | 6 +- src/SDK/Metrics/Data/HistogramDataPoint.php | 30 +++---- src/SDK/Metrics/Data/Metric.php | 18 ++-- src/SDK/Metrics/Data/NumberDataPoint.php | 15 ++-- src/SDK/Metrics/Data/Sum.php | 9 +- src/SDK/Metrics/Exemplar/BucketEntry.php | 10 +-- src/SDK/Metrics/Exemplar/BucketStorage.php | 6 +- .../Exemplar/ExemplarFilterInterface.php | 5 +- .../Exemplar/ExemplarReservoirInterface.php | 6 +- .../Metrics/Exemplar/FilteredReservoir.php | 4 +- .../Metrics/Exemplar/FixedSizeReservoir.php | 4 +- .../Exemplar/HistogramBucketReservoir.php | 2 +- src/SDK/Metrics/Instrument.php | 15 ++-- src/SDK/Metrics/Meter.php | 24 ++--- src/SDK/Metrics/MeterProvider.php | 24 ++--- .../MetricExporter/ConsoleMetricExporter.php | 7 +- .../MetricExporter/InMemoryExporter.php | 2 +- .../MetricFactory/StreamMetricSource.php | 4 +- .../StreamMetricSourceProvider.php | 21 ++--- .../Metrics/MetricReader/ExportingReader.php | 2 +- .../MultiRegistryRegistration.php | 4 +- .../RegistryRegistration.php | 4 +- .../Metrics/MetricRegistry/MetricRegistry.php | 6 +- .../Metrics/MetricRegistry/MultiObserver.php | 4 +- src/SDK/Metrics/ObservableCallback.php | 6 +- .../Metrics/ObservableCallbackDestructor.php | 2 +- .../DelayedStalenessHandler.php | 4 +- .../DelayedStalenessHandlerFactory.php | 11 +-- .../ImmediateStalenessHandlerFactory.php | 3 +- .../MultiReferenceCounter.php | 2 +- .../NoopStalenessHandlerFactory.php | 3 +- .../StalenessHandlerFactoryInterface.php | 5 +- .../Stream/AsynchronousMetricStream.php | 6 +- src/SDK/Metrics/Stream/DeltaStorage.php | 2 +- src/SDK/Metrics/Stream/MetricAggregator.php | 11 +-- .../Stream/MetricAggregatorFactory.php | 4 +- .../Stream/SynchronousMetricStream.php | 9 +- .../Stream/WritableMetricStreamInterface.php | 5 +- .../View/SelectionCriteria/AllCriteria.php | 2 +- .../InstrumentNameCriteria.php | 2 +- .../InstrumentTypeCriteria.php | 2 +- .../InstrumentationScopeNameCriteria.php | 2 +- .../InstrumentationScopeSchemaUrlCriteria.php | 2 +- .../InstrumentationScopeVersionCriteria.php | 2 +- src/SDK/Metrics/View/ViewTemplate.php | 4 +- src/SDK/Metrics/ViewProjection.php | 15 ++-- src/SDK/Resource/Detectors/Composite.php | 2 +- src/SDK/Resource/Detectors/Constant.php | 2 +- src/SDK/Sdk.php | 8 +- src/SDK/SdkAutoloader.php | 13 +-- src/SDK/SdkBuilder.php | 6 +- src/SDK/Trace/Event.php | 6 +- src/SDK/Trace/ImmutableSpan.php | 18 ++-- src/SDK/Trace/Link.php | 4 +- src/SDK/Trace/Sampler/ParentBased.php | 13 ++- .../Sampler/TraceIdRatioBasedSampler.php | 2 +- src/SDK/Trace/SamplingResult.php | 6 +- src/SDK/Trace/Span.php | 30 +++---- src/SDK/Trace/SpanBuilder.php | 9 +- .../SpanExporter/ConsoleSpanExporter.php | 2 +- .../Trace/SpanExporter/InMemoryExporter.php | 5 +- src/SDK/Trace/SpanLimits.php | 10 +-- .../SpanProcessor/BatchSpanProcessor.php | 6 +- .../BatchSpanProcessorBuilder.php | 2 +- .../SpanProcessor/SimpleSpanProcessor.php | 2 +- src/SDK/Trace/StatusData.php | 4 +- src/SDK/Trace/Tracer.php | 6 +- src/SDK/Trace/TracerProvider.php | 12 +-- src/SDK/Trace/TracerProviderFactory.php | 13 +-- src/SDK/Trace/TracerSharedState.php | 15 ++-- src/SDK/composer.json | 3 +- src/SemConv/composer.json | 2 +- tests/Integration/SDK/ParentBasedTest.php | 89 ------------------- 158 files changed, 393 insertions(+), 639 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 8d84acaef..314c64a5c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.0', '8.1', '8.2', '8.3'] + php-version: ['8.1', '8.2', '8.3'] experimental: [false] composer_args: [""] include: @@ -138,5 +138,5 @@ jobs: needs: php with: matrix_extension: '["ast, json, grpc"]' - matrix_php_version: '["8.0", "8.1", "8.2", "8.3"]' + matrix_php_version: '["8.1", "8.2", "8.3"]' install_directory: '~/.test/.packages' diff --git a/.phan/config.php b/.phan/config.php index 24b9eeaa5..13248372a 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -44,7 +44,7 @@ // // Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist. // (See `backward_compatibility_checks` for additional options) - 'target_php_version' => '8.0', + 'target_php_version' => '8.1', // If enabled, missing properties will be created when // they are first seen. If false, we'll report an diff --git a/composer.json b/composer.json index 059819d35..79ee954d8 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,7 @@ "readme": "./README.md", "license": "Apache-2.0", "require": { - "php": "^8.0", - "ext-json": "*", + "php": "^8.1", "google/protobuf": "^3.22", "php-http/discovery": "^1.14", "psr/http-client-implementation": "^1.0", @@ -17,7 +16,6 @@ "psr/http-message": "^1.0.1|^2.0", "psr/log": "^1.1|^2.0|^3.0", "symfony/polyfill-mbstring": "^1.23", - "symfony/polyfill-php81": "^1.26", "symfony/polyfill-php82": "^1.26" }, "config": { diff --git a/rector.php b/rector.php index 69f46d8e8..96ea2a92e 100644 --- a/rector.php +++ b/rector.php @@ -3,20 +3,25 @@ declare(strict_types=1); use Rector\CodeQuality\Rector\Array_\CallableThisArrayToAnonymousFunctionRector; +use Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector; use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; +use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; use Rector\Config\RectorConfig; +use Rector\Php81\Rector\ClassMethod\NewInInitializerRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; +use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\ValueObject\PhpVersion; use Rector\Set\ValueObject\SetList; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->phpVersion(PhpVersion::PHP_80); + $rectorConfig->phpVersion(PhpVersion::PHP_81); $rectorConfig->paths([ __DIR__ . '/src', ]); $rectorConfig->sets([ - SetList::PHP_80, + SetList::PHP_81, SetList::CODE_QUALITY, ]); $rectorConfig->skip([ @@ -25,8 +30,14 @@ __DIR__ . '/src/SDK/SdkAutoloader.php', ], FlipTypeControlToUseExclusiveTypeRector::class, - \Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector::class, - \Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector::class, - \Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector::class, + NewInInitializerRector::class => [ + __DIR__ . '/src/SDK/Trace/Sampler/ParentBased.php', + ], + ReadOnlyPropertyRector::class => [ + __DIR__ . '/src/SDK/Metrics/Stream/SynchronousMetricStream.php', + ], + DisallowedEmptyRuleFixerRector::class, + ExplicitBoolCompareRector::class, + LocallyCalledStaticMethodToNonStaticRector::class, ]); }; diff --git a/src/API/Baggage/Baggage.php b/src/API/Baggage/Baggage.php index e91e14bca..f39c1d004 100644 --- a/src/API/Baggage/Baggage.php +++ b/src/API/Baggage/Baggage.php @@ -42,7 +42,7 @@ public static function getEmpty(): BaggageInterface } /** @param array $entries */ - public function __construct(private array $entries = []) + public function __construct(private readonly array $entries = []) { } diff --git a/src/API/Baggage/Entry.php b/src/API/Baggage/Entry.php index 659f166cc..2e5950d43 100644 --- a/src/API/Baggage/Entry.php +++ b/src/API/Baggage/Entry.php @@ -7,8 +7,8 @@ final class Entry { public function __construct( - private mixed $value, - private MetadataInterface $metadata, + private readonly mixed $value, + private readonly MetadataInterface $metadata, ) { } diff --git a/src/API/Baggage/Metadata.php b/src/API/Baggage/Metadata.php index bf2a4fbf4..5339a6da4 100644 --- a/src/API/Baggage/Metadata.php +++ b/src/API/Baggage/Metadata.php @@ -13,7 +13,7 @@ public static function getEmpty(): Metadata return self::$instance ??= new self(''); } - public function __construct(private string $metadata) + public function __construct(private readonly string $metadata) { } diff --git a/src/API/Baggage/Propagation/BaggagePropagator.php b/src/API/Baggage/Propagation/BaggagePropagator.php index fae62dcab..964868705 100644 --- a/src/API/Baggage/Propagation/BaggagePropagator.php +++ b/src/API/Baggage/Propagation/BaggagePropagator.php @@ -54,7 +54,7 @@ public function inject(&$carrier, PropagationSetterInterface $setter = null, Con /** @var Entry $entry */ foreach ($baggage->getAll() as $key => $entry) { - $value = urlencode($entry->getValue()); + $value = urlencode((string) $entry->getValue()); $headerString.= "{$key}={$value}"; if (($metadata = $entry->getMetadata()->getValue()) !== '' && ($metadata = $entry->getMetadata()->getValue()) !== '0') { diff --git a/src/API/Baggage/Propagation/Parser.php b/src/API/Baggage/Propagation/Parser.php index 34fa2c80c..b87d6bb9d 100644 --- a/src/API/Baggage/Propagation/Parser.php +++ b/src/API/Baggage/Propagation/Parser.php @@ -18,8 +18,7 @@ final class Parser private const EQUALS = '='; public function __construct( - /** @readonly */ - private string $baggageHeader, + private readonly string $baggageHeader, ) { } diff --git a/src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php b/src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php index c83b2631e..5c7c8a620 100644 --- a/src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php +++ b/src/API/Behavior/Internal/LogWriter/Psr3LogWriter.php @@ -8,7 +8,7 @@ class Psr3LogWriter implements LogWriterInterface { - public function __construct(private LoggerInterface $logger) + public function __construct(private readonly LoggerInterface $logger) { } diff --git a/src/API/Globals.php b/src/API/Globals.php index 7256c1ac7..51fe8edbf 100644 --- a/src/API/Globals.php +++ b/src/API/Globals.php @@ -28,10 +28,10 @@ final class Globals private static ?self $globals = null; public function __construct( - private TracerProviderInterface $tracerProvider, - private MeterProviderInterface $meterProvider, - private LoggerProviderInterface $loggerProvider, - private TextMapPropagatorInterface $propagator, + private readonly TracerProviderInterface $tracerProvider, + private readonly MeterProviderInterface $meterProvider, + private readonly LoggerProviderInterface $loggerProvider, + private readonly TextMapPropagatorInterface $propagator, ) { } diff --git a/src/API/Instrumentation/CachedInstrumentation.php b/src/API/Instrumentation/CachedInstrumentation.php index 18609b66b..deb0f58f2 100644 --- a/src/API/Instrumentation/CachedInstrumentation.php +++ b/src/API/Instrumentation/CachedInstrumentation.php @@ -34,10 +34,10 @@ final class CachedInstrumentation * @psalm-suppress PropertyTypeCoercion */ public function __construct( - private string $name, - private ?string $version = null, - private ?string $schemaUrl = null, - private iterable $attributes = [], + private readonly string $name, + private readonly ?string $version = null, + private readonly ?string $schemaUrl = null, + private readonly iterable $attributes = [], ) { $this->tracers = new \WeakMap(); $this->meters = new \WeakMap(); diff --git a/src/API/Logs/EventLogger.php b/src/API/Logs/EventLogger.php index 89e942ce7..abbe54b97 100644 --- a/src/API/Logs/EventLogger.php +++ b/src/API/Logs/EventLogger.php @@ -7,8 +7,8 @@ class EventLogger implements EventLoggerInterface { public function __construct( - private LoggerInterface $logger, - private string $domain, + private readonly LoggerInterface $logger, + private readonly string $domain, ) { } diff --git a/src/API/Trace/NonRecordingSpan.php b/src/API/Trace/NonRecordingSpan.php index b94d46305..21e1eacd4 100644 --- a/src/API/Trace/NonRecordingSpan.php +++ b/src/API/Trace/NonRecordingSpan.php @@ -13,7 +13,7 @@ */ final class NonRecordingSpan extends Span { - public function __construct(private SpanContextInterface $context) + public function __construct(private readonly SpanContextInterface $context) { } diff --git a/src/API/Trace/NoopSpanBuilder.php b/src/API/Trace/NoopSpanBuilder.php index 024118d35..c7a2f295a 100644 --- a/src/API/Trace/NoopSpanBuilder.php +++ b/src/API/Trace/NoopSpanBuilder.php @@ -12,7 +12,7 @@ final class NoopSpanBuilder implements SpanBuilderInterface { private ContextInterface|false|null $parentContext = null; - public function __construct(private ContextStorageInterface $contextStorage) + public function __construct(private readonly ContextStorageInterface $contextStorage) { } diff --git a/src/API/Trace/SpanContext.php b/src/API/Trace/SpanContext.php index 7724def86..3e46154d7 100644 --- a/src/API/Trace/SpanContext.php +++ b/src/API/Trace/SpanContext.php @@ -14,15 +14,15 @@ final class SpanContext implements SpanContextInterface * @see https://www.w3.org/TR/trace-context/#trace-flags * @see https://www.w3.org/TR/trace-context/#sampled-flag */ - private bool $isSampled; + private readonly bool $isSampled; private bool $isValid = true; private function __construct( private string $traceId, private string $spanId, - private int $traceFlags, - private bool $isRemote, - private ?TraceStateInterface $traceState = null, + private readonly int $traceFlags, + private readonly bool $isRemote, + private readonly ?TraceStateInterface $traceState = null, ) { // TraceId must be exactly 16 bytes (32 chars) and at least one non-zero byte // SpanId must be exactly 8 bytes (16 chars) and at least one non-zero byte diff --git a/src/API/Trace/TraceState.php b/src/API/Trace/TraceState.php index 306a63322..b398f2dba 100644 --- a/src/API/Trace/TraceState.php +++ b/src/API/Trace/TraceState.php @@ -23,9 +23,7 @@ class TraceState implements TraceStateInterface private const VALID_VALUE_BASE_REGEX = '/^[ -~]{0,255}[!-~]$/'; private const INVALID_VALUE_COMMA_EQUAL_REGEX = '/,|=/'; - /** - * @var string[] - */ + /** @var string[] */ private array $traceState = []; public function __construct(string $rawTracestate = null) diff --git a/src/API/composer.json b/src/API/composer.json index 78c9c5ee0..89255325a 100644 --- a/src/API/composer.json +++ b/src/API/composer.json @@ -17,10 +17,9 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "open-telemetry/context": "^1.0", "psr/log": "^1.1|^2.0|^3.0", - "symfony/polyfill-php81": "^1.26", "symfony/polyfill-php82": "^1.26" }, "conflict": { diff --git a/src/Context/Context.php b/src/Context/Context.php index 278c27d3e..55715f03b 100644 --- a/src/Context/Context.php +++ b/src/Context/Context.php @@ -16,8 +16,7 @@ final class Context implements ContextInterface { private const OTEL_PHP_DEBUG_SCOPES_DISABLED = 'OTEL_PHP_DEBUG_SCOPES_DISABLED'; - /** @var ContextStorageInterface&ExecutionContextAwareInterface */ - private static ContextStorageInterface $storage; + private static ContextStorageInterface&ExecutionContextAwareInterface $storage; // Optimization for spans to avoid copying the context array. private static ContextKeyInterface $spanContextKey; @@ -37,20 +36,12 @@ public static function createKey(string $key): ContextKeyInterface return new ContextKey($key); } - /** - * @param ContextStorageInterface&ExecutionContextAwareInterface $storage - * @todo update type-hint (php >= 8.1) - */ - public static function setStorage(ContextStorageInterface $storage): void + public static function setStorage(ContextStorageInterface&ExecutionContextAwareInterface $storage): void { self::$storage = $storage; } - /** - * @return ContextStorageInterface&ExecutionContextAwareInterface - * @todo update return type-hint (php >= 8.1) - */ - public static function storage(): ContextStorageInterface + public static function storage(): ContextStorageInterface&ExecutionContextAwareInterface { /** @psalm-suppress RedundantPropertyInitializationCheck */ return self::$storage ??= new ContextStorage(); diff --git a/src/Context/ContextKey.php b/src/Context/ContextKey.php index 08466e3a8..476bf2031 100644 --- a/src/Context/ContextKey.php +++ b/src/Context/ContextKey.php @@ -10,7 +10,7 @@ */ final class ContextKey implements ContextKeyInterface { - public function __construct(private ?string $name = null) + public function __construct(private readonly ?string $name = null) { } diff --git a/src/Context/ContextStorage.php b/src/Context/ContextStorage.php index e82d3d161..1f9057892 100644 --- a/src/Context/ContextStorage.php +++ b/src/Context/ContextStorage.php @@ -19,17 +19,17 @@ public function __construct() $this->current = $this->main = new ContextStorageHead($this); } - public function fork($id): void + public function fork(int|string $id): void { $this->forks[$id] = clone $this->current; } - public function switch($id): void + public function switch(int|string $id): void { $this->current = $this->forks[$id] ?? $this->main; } - public function destroy($id): void + public function destroy(int|string $id): void { unset($this->forks[$id]); } diff --git a/src/Context/DebugScope.php b/src/Context/DebugScope.php index 437234e40..f78a4ce6a 100644 --- a/src/Context/DebugScope.php +++ b/src/Context/DebugScope.php @@ -24,11 +24,11 @@ final class DebugScope implements ScopeInterface { private static bool $shutdownHandlerInitialized = false; private static bool $finalShutdownPhase = false; - private ?int $fiberId; - private array $createdAt; + private readonly ?int $fiberId; + private readonly array $createdAt; private ?array $detachedAt = null; - public function __construct(private ContextStorageScopeInterface $scope) + public function __construct(private readonly ContextStorageScopeInterface $scope) { $this->fiberId = self::currentFiberId(); $this->createdAt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); @@ -114,7 +114,7 @@ private static function formatBacktrace(array $trace): string $s .= strtr($trace[$i]['function'] ?? '{main}', ['\\' => '.']); $s .= '('; if (isset($trace[$i - 1]['file'])) { - $s .= basename($trace[$i - 1]['file']); + $s .= basename((string) $trace[$i - 1]['file']); if (isset($trace[$i - 1]['line'])) { $s .= ':'; $s .= $trace[$i - 1]['line']; diff --git a/src/Context/ExecutionContextAwareInterface.php b/src/Context/ExecutionContextAwareInterface.php index 3a955bfae..fbf5998d0 100644 --- a/src/Context/ExecutionContextAwareInterface.php +++ b/src/Context/ExecutionContextAwareInterface.php @@ -6,18 +6,9 @@ interface ExecutionContextAwareInterface { - /** - * @param int|string $id - */ - public function fork($id): void; + public function fork(int|string $id): void; - /** - * @param int|string $id - */ - public function switch($id): void; + public function switch(int|string $id): void; - /** - * @param int|string $id - */ - public function destroy($id): void; + public function destroy(int|string $id): void; } diff --git a/src/Context/FiberBoundContextStorage.php b/src/Context/FiberBoundContextStorage.php index 180846f91..d55aa0399 100644 --- a/src/Context/FiberBoundContextStorage.php +++ b/src/Context/FiberBoundContextStorage.php @@ -20,24 +20,21 @@ */ final class FiberBoundContextStorage implements ContextStorageInterface, ExecutionContextAwareInterface { - /** - * @param ContextStorageInterface&ExecutionContextAwareInterface $storage - */ - public function __construct(private ContextStorageInterface $storage) + public function __construct(private readonly ContextStorageInterface&ExecutionContextAwareInterface $storage) { } - public function fork($id): void + public function fork(int|string $id): void { $this->storage->fork($id); } - public function switch($id): void + public function switch(int|string $id): void { $this->storage->switch($id); } - public function destroy($id): void + public function destroy(int|string $id): void { $this->storage->destroy($id); } diff --git a/src/Context/Propagation/MultiTextMapPropagator.php b/src/Context/Propagation/MultiTextMapPropagator.php index 9a81324fc..36936f467 100644 --- a/src/Context/Propagation/MultiTextMapPropagator.php +++ b/src/Context/Propagation/MultiTextMapPropagator.php @@ -13,11 +13,8 @@ final class MultiTextMapPropagator implements TextMapPropagatorInterface { - /** - * @readonly - * @var list - */ - private array $fields; + /** @var list */ + private readonly array $fields; /** * @no-named-arguments @@ -25,8 +22,7 @@ final class MultiTextMapPropagator implements TextMapPropagatorInterface * @param list $propagators */ public function __construct( - /** @readonly */ - private array $propagators, + private readonly array $propagators, ) { $this->fields = $this->extractFields($this->propagators); } diff --git a/src/Context/Propagation/SanitizeCombinedHeadersPropagationGetter.php b/src/Context/Propagation/SanitizeCombinedHeadersPropagationGetter.php index cab2b7b19..bfad5d03c 100644 --- a/src/Context/Propagation/SanitizeCombinedHeadersPropagationGetter.php +++ b/src/Context/Propagation/SanitizeCombinedHeadersPropagationGetter.php @@ -18,7 +18,7 @@ final class SanitizeCombinedHeadersPropagationGetter implements PropagationGette private const SERVER_CONCAT_HEADERS_REGEX = '/;(?=[^,=;]*=|$)/'; private const TRAILING_LEADING_SEPARATOR_REGEX = '/^' . self::LIST_MEMBERS_SEPARATOR . '+|' . self::LIST_MEMBERS_SEPARATOR . '+$/'; - public function __construct(private PropagationGetterInterface $getter) + public function __construct(private readonly PropagationGetterInterface $getter) { } diff --git a/src/Context/composer.json b/src/Context/composer.json index ee191de9b..2717e8e3b 100644 --- a/src/Context/composer.json +++ b/src/Context/composer.json @@ -17,8 +17,7 @@ } ], "require": { - "php": "^8.0", - "symfony/polyfill-php81": "^1.26", + "php": "^8.1", "symfony/polyfill-php82": "^1.26" }, "autoload": { diff --git a/src/Contrib/Grpc/GrpcTransport.php b/src/Contrib/Grpc/GrpcTransport.php index 338b89b3b..6268eecef 100644 --- a/src/Contrib/Grpc/GrpcTransport.php +++ b/src/Contrib/Grpc/GrpcTransport.php @@ -35,14 +35,14 @@ */ final class GrpcTransport implements TransportInterface { - private array $metadata; - private Channel $channel; + private readonly array $metadata; + private readonly Channel $channel; private bool $closed = false; public function __construct( string $endpoint, array $opts, - private string $method, + private readonly string $method, array $headers = [], ) { $this->channel = new Channel($endpoint, $opts); diff --git a/src/Contrib/Grpc/composer.json b/src/Contrib/Grpc/composer.json index 96b829741..ad5efd0e3 100644 --- a/src/Contrib/Grpc/composer.json +++ b/src/Contrib/Grpc/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "ext-grpc": "*", "grpc/grpc": "*", "open-telemetry/sdk": "^1.0" diff --git a/src/Contrib/Otlp/HttpEndpointResolver.php b/src/Contrib/Otlp/HttpEndpointResolver.php index b50346427..e63eec4b5 100644 --- a/src/Contrib/Otlp/HttpEndpointResolver.php +++ b/src/Contrib/Otlp/HttpEndpointResolver.php @@ -25,7 +25,7 @@ class HttpEndpointResolver implements HttpEndpointResolverInterface private const DEFAULT_SCHEME = 'https'; private const ROOT_PATH = '/'; - private FactoryResolverInterface $httpFactoryResolver; + private readonly FactoryResolverInterface $httpFactoryResolver; public function __construct(?FactoryResolverInterface $httpFactoryResolver = null) { diff --git a/src/Contrib/Otlp/LogsConverter.php b/src/Contrib/Otlp/LogsConverter.php index 1da53ad1f..2ee2f973a 100644 --- a/src/Contrib/Otlp/LogsConverter.php +++ b/src/Contrib/Otlp/LogsConverter.php @@ -18,7 +18,7 @@ class LogsConverter { - private ProtobufSerializer $serializer; + private readonly ProtobufSerializer $serializer; public function __construct(?ProtobufSerializer $serializer = null) { diff --git a/src/Contrib/Otlp/LogsExporterFactory.php b/src/Contrib/Otlp/LogsExporterFactory.php index f588cfa27..c70b1649d 100644 --- a/src/Contrib/Otlp/LogsExporterFactory.php +++ b/src/Contrib/Otlp/LogsExporterFactory.php @@ -18,7 +18,7 @@ class LogsExporterFactory implements LogRecordExporterFactoryInterface { private const DEFAULT_COMPRESSION = 'none'; - public function __construct(private ?TransportFactoryInterface $transportFactory = null) + public function __construct(private readonly ?TransportFactoryInterface $transportFactory = null) { } diff --git a/src/Contrib/Otlp/MetricConverter.php b/src/Contrib/Otlp/MetricConverter.php index ba3a0b42b..eb46f547f 100644 --- a/src/Contrib/Otlp/MetricConverter.php +++ b/src/Contrib/Otlp/MetricConverter.php @@ -27,7 +27,7 @@ final class MetricConverter { - private ProtobufSerializer $serializer; + private readonly ProtobufSerializer $serializer; public function __construct(?ProtobufSerializer $serializer = null) { diff --git a/src/Contrib/Otlp/MetricExporter.php b/src/Contrib/Otlp/MetricExporter.php index 8025766bd..c5a9ad6bc 100644 --- a/src/Contrib/Otlp/MetricExporter.php +++ b/src/Contrib/Otlp/MetricExporter.php @@ -28,8 +28,8 @@ final class MetricExporter implements PushMetricExporterInterface, AggregationTe * @psalm-param TransportInterface $transport */ public function __construct( - private TransportInterface $transport, - private string|Temporality|null $temporality = null, + private readonly TransportInterface $transport, + private readonly string|Temporality|null $temporality = null, ) { if (!class_exists('\Google\Protobuf\Api')) { throw new RuntimeException('No protobuf implementation found (ext-protobuf or google/protobuf)'); @@ -37,7 +37,7 @@ public function __construct( $this->serializer = ProtobufSerializer::forTransport($this->transport); } - public function temporality(MetricMetadataInterface $metric) + public function temporality(MetricMetadataInterface $metric): Temporality|string|null { return $this->temporality ?? $metric->temporality(); } diff --git a/src/Contrib/Otlp/MetricExporterFactory.php b/src/Contrib/Otlp/MetricExporterFactory.php index 8a201fd53..d59ecdc64 100644 --- a/src/Contrib/Otlp/MetricExporterFactory.php +++ b/src/Contrib/Otlp/MetricExporterFactory.php @@ -19,7 +19,7 @@ class MetricExporterFactory implements MetricExporterFactoryInterface { private const DEFAULT_COMPRESSION = 'none'; - public function __construct(private ?TransportFactoryInterface $transportFactory = null) + public function __construct(private readonly ?TransportFactoryInterface $transportFactory = null) { } diff --git a/src/Contrib/Otlp/ProtobufSerializer.php b/src/Contrib/Otlp/ProtobufSerializer.php index f8897d193..dd4b58c3c 100644 --- a/src/Contrib/Otlp/ProtobufSerializer.php +++ b/src/Contrib/Otlp/ProtobufSerializer.php @@ -30,7 +30,7 @@ */ final class ProtobufSerializer { - private function __construct(private string $contentType) + private function __construct(private readonly string $contentType) { } @@ -120,7 +120,7 @@ private static function traverseDescriptor(object $data, Descriptor $desc): void for ($i = 0, $n = $desc->getFieldCount(); $i < $n; $i++) { // @phan-suppress-next-line PhanParamTooManyInternal $field = $desc->getField($i); - $name = lcfirst(strtr(ucwords($field->getName(), '_'), ['_' => ''])); + $name = lcfirst(strtr(ucwords((string) $field->getName(), '_'), ['_' => ''])); if (!property_exists($data, $name)) { continue; } diff --git a/src/Contrib/Otlp/SpanConverter.php b/src/Contrib/Otlp/SpanConverter.php index fba1e9727..9f3be3ca3 100644 --- a/src/Contrib/Otlp/SpanConverter.php +++ b/src/Contrib/Otlp/SpanConverter.php @@ -26,7 +26,7 @@ final class SpanConverter { - private ProtobufSerializer $serializer; + private readonly ProtobufSerializer $serializer; public function __construct(?ProtobufSerializer $serializer = null) { diff --git a/src/Contrib/Otlp/composer.json b/src/Contrib/Otlp/composer.json index 519a09a63..0232953c6 100644 --- a/src/Contrib/Otlp/composer.json +++ b/src/Contrib/Otlp/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "php-http/discovery": "^1.14", "open-telemetry/gen-otlp-protobuf": "^1.1", "open-telemetry/api": "^1.0", diff --git a/src/Contrib/Zipkin/Exporter.php b/src/Contrib/Zipkin/Exporter.php index ef5298c00..294883aa1 100644 --- a/src/Contrib/Zipkin/Exporter.php +++ b/src/Contrib/Zipkin/Exporter.php @@ -24,7 +24,7 @@ class Exporter implements SpanExporterInterface use UsesSpanConverterTrait; public function __construct( - private TransportInterface $transport, + private readonly TransportInterface $transport, SpanConverterInterface $spanConverter = null, ) { $this->setSpanConverter($spanConverter ?? new SpanConverter()); diff --git a/src/Contrib/Zipkin/SpanConverter.php b/src/Contrib/Zipkin/SpanConverter.php index 9f00d514a..d46cfc78d 100644 --- a/src/Contrib/Zipkin/SpanConverter.php +++ b/src/Contrib/Zipkin/SpanConverter.php @@ -37,7 +37,7 @@ class SpanConverter implements SpanConverterInterface const NET_PEER_IP_KEY = 'net.peer.ip'; - private string $defaultServiceName; + private readonly string $defaultServiceName; public function __construct() { diff --git a/src/Contrib/Zipkin/composer.json b/src/Contrib/Zipkin/composer.json index 4eb7604b5..838d0581c 100644 --- a/src/Contrib/Zipkin/composer.json +++ b/src/Contrib/Zipkin/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "open-telemetry/api": "^1.0", "open-telemetry/sdk": "^1.0", "php-http/async-client-implementation": "^1.0", diff --git a/src/Contrib/composer.json b/src/Contrib/composer.json index 603aaeb5f..e2a187e0a 100644 --- a/src/Contrib/composer.json +++ b/src/Contrib/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "ext-json": "*", "open-telemetry/api": "^1.0", "open-telemetry/context": "^1.0", @@ -23,7 +23,6 @@ "psr/http-factory-implementation": "^1.0", "psr/log": "^1.1|^2.0|^3.0", "symfony/polyfill-mbstring": "^1.23", - "symfony/polyfill-php81": "^1.26", "symfony/polyfill-php82": "^1.26" }, "autoload": { diff --git a/src/Extension/Propagator/B3/B3Propagator.php b/src/Extension/Propagator/B3/B3Propagator.php index d796049f6..1c91c6145 100644 --- a/src/Extension/Propagator/B3/B3Propagator.php +++ b/src/Extension/Propagator/B3/B3Propagator.php @@ -18,7 +18,7 @@ */ final class B3Propagator implements TextMapPropagatorInterface { - private function __construct(private TextMapPropagatorInterface $propagator) + private function __construct(private readonly TextMapPropagatorInterface $propagator) { } diff --git a/src/Extension/Propagator/B3/B3SinglePropagator.php b/src/Extension/Propagator/B3/B3SinglePropagator.php index 67ef62f11..56160ff1a 100644 --- a/src/Extension/Propagator/B3/B3SinglePropagator.php +++ b/src/Extension/Propagator/B3/B3SinglePropagator.php @@ -97,15 +97,15 @@ private static function processSampledValue($value): ?int return null; } - if (strtolower($value) === self::IS_DEBUG) { + if (strtolower((string) $value) === self::IS_DEBUG) { return (int) self::IS_SAMPLED; } - if (in_array(strtolower($value), self::VALID_SAMPLED)) { + if (in_array(strtolower((string) $value), self::VALID_SAMPLED)) { return (int) self::IS_SAMPLED; } - if (in_array(strtolower($value), self::VALID_NON_SAMPLED)) { + if (in_array(strtolower((string) $value), self::VALID_NON_SAMPLED)) { return (int) self::IS_NOT_SAMPLED; } diff --git a/src/Extension/Propagator/B3/composer.json b/src/Extension/Propagator/B3/composer.json index c7c094c52..240c38dff 100644 --- a/src/Extension/Propagator/B3/composer.json +++ b/src/Extension/Propagator/B3/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "open-telemetry/api": "^1.0", "open-telemetry/context": "^1.0" }, diff --git a/src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php b/src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php index 1309cfddc..f64d32e7d 100644 --- a/src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php +++ b/src/Extension/Propagator/CloudTrace/CloudTraceFormatter.php @@ -38,7 +38,7 @@ public static function deserialize(string $header) : SpanContextInterface return SpanContext::createFromRemoteParent( strtolower($matches[1]), Utils::leftZeroPad(Utils::decToHex($matches[2])), - (int) ($matches[3] == '1') + (int) ($matches[3] === '1') ); } diff --git a/src/Extension/Propagator/CloudTrace/CloudTracePropagator.php b/src/Extension/Propagator/CloudTrace/CloudTracePropagator.php index 60d59a1c9..5e2cf7787 100644 --- a/src/Extension/Propagator/CloudTrace/CloudTracePropagator.php +++ b/src/Extension/Propagator/CloudTrace/CloudTracePropagator.php @@ -46,7 +46,7 @@ public static function getInstance(): TextMapPropagatorInterface self::XCLOUD, ]; - private function __construct(private bool $oneWay) + private function __construct(private readonly bool $oneWay) { } diff --git a/src/Extension/Propagator/CloudTrace/composer.json b/src/Extension/Propagator/CloudTrace/composer.json index 216f730c8..14472620e 100644 --- a/src/Extension/Propagator/CloudTrace/composer.json +++ b/src/Extension/Propagator/CloudTrace/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "open-telemetry/api": "^1.0", "open-telemetry/context": "^1.0" }, diff --git a/src/Extension/Propagator/Jaeger/composer.json b/src/Extension/Propagator/Jaeger/composer.json index add41c42a..5fd72a785 100644 --- a/src/Extension/Propagator/Jaeger/composer.json +++ b/src/Extension/Propagator/Jaeger/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.1", "open-telemetry/api": "^1.0", "open-telemetry/context": "^1.0" }, diff --git a/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php index 057e4434d..7589d6b05 100644 --- a/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php +++ b/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php @@ -19,9 +19,9 @@ final class DependencyResolver implements DependencyResolverInterface { - private MessageFactoryResolverInterface $messageFactoryResolver; - private PsrClientResolverInterface $psrClientResolver; - private HttpPlugClientResolverInterface $httpPlugClientResolver; + private readonly MessageFactoryResolverInterface $messageFactoryResolver; + private readonly PsrClientResolverInterface $psrClientResolver; + private readonly HttpPlugClientResolverInterface $httpPlugClientResolver; public function __construct( ?MessageFactoryResolverInterface $messageFactoryResolver = null, diff --git a/src/SDK/Common/Attribute/Attributes.php b/src/SDK/Common/Attribute/Attributes.php index c75944040..800a10f4b 100644 --- a/src/SDK/Common/Attribute/Attributes.php +++ b/src/SDK/Common/Attribute/Attributes.php @@ -17,8 +17,8 @@ final class Attributes implements AttributesInterface, IteratorAggregate * @internal */ public function __construct( - private array $attributes, - private int $droppedAttributesCount, + private readonly array $attributes, + private readonly int $droppedAttributesCount, ) { } diff --git a/src/SDK/Common/Attribute/AttributesBuilder.php b/src/SDK/Common/Attribute/AttributesBuilder.php index cd3232a46..bb3533076 100644 --- a/src/SDK/Common/Attribute/AttributesBuilder.php +++ b/src/SDK/Common/Attribute/AttributesBuilder.php @@ -17,16 +17,9 @@ final class AttributesBuilder implements AttributesBuilderInterface { use LogsMessagesTrait; - private AttributeValidatorInterface $attributeValidator; - - public function __construct( - private array $attributes, - private ?int $attributeCountLimit, - private ?int $attributeValueLengthLimit, - private int $droppedAttributesCount, - ?AttributeValidatorInterface $attributeValidator, - ) { - $this->attributeValidator = $attributeValidator ?? new AttributeValidator(); + + public function __construct(private array $attributes, private ?int $attributeCountLimit, private ?int $attributeValueLengthLimit, private int $droppedAttributesCount, private AttributeValidatorInterface $attributeValidator = new AttributeValidator()) + { } public function build(): AttributesInterface diff --git a/src/SDK/Common/Attribute/AttributesFactory.php b/src/SDK/Common/Attribute/AttributesFactory.php index 8e072c7ab..c868efd5e 100644 --- a/src/SDK/Common/Attribute/AttributesFactory.php +++ b/src/SDK/Common/Attribute/AttributesFactory.php @@ -10,8 +10,8 @@ final class AttributesFactory implements AttributesFactoryInterface { public function __construct( - private ?int $attributeCountLimit = null, - private ?int $attributeValueLengthLimit = null, + private readonly ?int $attributeCountLimit = null, + private readonly ?int $attributeValueLengthLimit = null, ) { } @@ -22,7 +22,7 @@ public function builder(iterable $attributes = [], ?AttributeValidatorInterface $this->attributeCountLimit, $this->attributeValueLengthLimit, 0, - $attributeValidator, + $attributeValidator ?? new AttributeValidator(), ); foreach ($attributes as $key => $value) { $builder[$key] = $value; diff --git a/src/SDK/Common/Attribute/FilteredAttributesBuilder.php b/src/SDK/Common/Attribute/FilteredAttributesBuilder.php index a0269ea49..3162ac5dd 100644 --- a/src/SDK/Common/Attribute/FilteredAttributesBuilder.php +++ b/src/SDK/Common/Attribute/FilteredAttributesBuilder.php @@ -18,7 +18,7 @@ final class FilteredAttributesBuilder implements AttributesBuilderInterface */ public function __construct( private AttributesBuilderInterface $builder, - private array $rejectedKeys, + private readonly array $rejectedKeys, ) { } diff --git a/src/SDK/Common/Attribute/FilteredAttributesFactory.php b/src/SDK/Common/Attribute/FilteredAttributesFactory.php index fca0ce492..d6ad75c6f 100644 --- a/src/SDK/Common/Attribute/FilteredAttributesFactory.php +++ b/src/SDK/Common/Attribute/FilteredAttributesFactory.php @@ -13,8 +13,8 @@ final class FilteredAttributesFactory implements AttributesFactoryInterface * @param list $rejectedKeys */ public function __construct( - private AttributesFactoryInterface $factory, - private array $rejectedKeys, + private readonly AttributesFactoryInterface $factory, + private readonly array $rejectedKeys, ) { } diff --git a/src/SDK/Common/Configuration/Parser/MapParser.php b/src/SDK/Common/Configuration/Parser/MapParser.php index e059662bf..b6404bb70 100644 --- a/src/SDK/Common/Configuration/Parser/MapParser.php +++ b/src/SDK/Common/Configuration/Parser/MapParser.php @@ -18,11 +18,11 @@ public static function parse($value): array } $result = []; - if (null === $value || trim($value) === '') { + if (null === $value || trim((string) $value) === '') { return $result; } - foreach (explode(self::VARIABLE_SEPARATOR, $value) as $pair) { + foreach (explode(self::VARIABLE_SEPARATOR, (string) $value) as $pair) { self::validateKeyValuePair($pair); /** @psalm-suppress PossiblyUndefinedArrayOffset */ diff --git a/src/SDK/Common/Configuration/Resolver/CompositeResolver.php b/src/SDK/Common/Configuration/Resolver/CompositeResolver.php index 1160129be..1054b6239 100644 --- a/src/SDK/Common/Configuration/Resolver/CompositeResolver.php +++ b/src/SDK/Common/Configuration/Resolver/CompositeResolver.php @@ -11,7 +11,7 @@ */ class CompositeResolver { - // @var array + /** @var list */ private array $resolvers = []; public static function instance(): self diff --git a/src/SDK/Common/Configuration/Resolver/PhpIniResolver.php b/src/SDK/Common/Configuration/Resolver/PhpIniResolver.php index 6f7db258d..29445dd88 100644 --- a/src/SDK/Common/Configuration/Resolver/PhpIniResolver.php +++ b/src/SDK/Common/Configuration/Resolver/PhpIniResolver.php @@ -12,11 +12,8 @@ */ class PhpIniResolver implements ResolverInterface { - private PhpIniAccessor $accessor; - - public function __construct(?PhpIniAccessor $accessor = null) + public function __construct(private readonly PhpIniAccessor $accessor = new PhpIniAccessor()) { - $this->accessor = $accessor ?? new PhpIniAccessor(); } public function retrieveValue(string $variableName) diff --git a/src/SDK/Common/Export/Http/PsrTransport.php b/src/SDK/Common/Export/Http/PsrTransport.php index d12acd725..ef3ab02b4 100644 --- a/src/SDK/Common/Export/Http/PsrTransport.php +++ b/src/SDK/Common/Export/Http/PsrTransport.php @@ -36,15 +36,15 @@ final class PsrTransport implements TransportInterface * @psalm-param CONTENT_TYPE $contentType */ public function __construct( - private ClientInterface $client, - private RequestFactoryInterface $requestFactory, - private StreamFactoryInterface $streamFactory, - private string $endpoint, - private string $contentType, - private array $headers, - private array $compression, - private int $retryDelay, - private int $maxRetries, + private readonly ClientInterface $client, + private readonly RequestFactoryInterface $requestFactory, + private readonly StreamFactoryInterface $streamFactory, + private readonly string $endpoint, + private readonly string $contentType, + private readonly array $headers, + private readonly array $compression, + private readonly int $retryDelay, + private readonly int $maxRetries, ) { } diff --git a/src/SDK/Common/Export/Http/PsrTransportFactory.php b/src/SDK/Common/Export/Http/PsrTransportFactory.php index 200f7d1ba..1249d1eac 100644 --- a/src/SDK/Common/Export/Http/PsrTransportFactory.php +++ b/src/SDK/Common/Export/Http/PsrTransportFactory.php @@ -17,9 +17,9 @@ final class PsrTransportFactory implements TransportFactoryInterface { public function __construct( - private ClientInterface $client, - private RequestFactoryInterface $requestFactory, - private StreamFactoryInterface $streamFactory, + private readonly ClientInterface $client, + private readonly RequestFactoryInterface $requestFactory, + private readonly StreamFactoryInterface $streamFactory, ) { } diff --git a/src/SDK/Common/Export/Http/PsrUtils.php b/src/SDK/Common/Export/Http/PsrUtils.php index 33cd0c7e4..79aaee832 100644 --- a/src/SDK/Common/Export/Http/PsrUtils.php +++ b/src/SDK/Common/Export/Http/PsrUtils.php @@ -116,11 +116,11 @@ public static function compression($compression): array if (!$compression) { return []; } - if (!str_contains($compression, ',')) { + if (!str_contains((string) $compression, ',')) { return [$compression]; } - return array_map('trim', explode(',', $compression)); + return array_map('trim', explode(',', (string) $compression)); } private static function encoder(string $encoding): ?callable diff --git a/src/SDK/Common/Export/Stream/StreamTransport.php b/src/SDK/Common/Export/Stream/StreamTransport.php index e22295cb6..6b3bf6351 100644 --- a/src/SDK/Common/Export/Stream/StreamTransport.php +++ b/src/SDK/Common/Export/Stream/StreamTransport.php @@ -34,7 +34,7 @@ final class StreamTransport implements TransportInterface */ public function __construct( private $stream, - private string $contentType, + private readonly string $contentType, ) { } diff --git a/src/SDK/Common/Future/ErrorFuture.php b/src/SDK/Common/Future/ErrorFuture.php index 061cde54f..90e3f5495 100644 --- a/src/SDK/Common/Future/ErrorFuture.php +++ b/src/SDK/Common/Future/ErrorFuture.php @@ -12,11 +12,11 @@ */ final class ErrorFuture implements FutureInterface { - public function __construct(private Throwable $throwable) + public function __construct(private readonly Throwable $throwable) { } - public function await() + public function await(): never { throw $this->throwable; } diff --git a/src/SDK/Common/Http/Psr/Message/MessageFactory.php b/src/SDK/Common/Http/Psr/Message/MessageFactory.php index 63aac0850..87e662f79 100644 --- a/src/SDK/Common/Http/Psr/Message/MessageFactory.php +++ b/src/SDK/Common/Http/Psr/Message/MessageFactory.php @@ -14,9 +14,9 @@ final class MessageFactory implements MessageFactoryInterface { public function __construct( - private RequestFactoryInterface $requestFactory, - private ResponseFactoryInterface $responseFactory, - private ServerRequestFactoryInterface $serverRequestFactory, + private readonly RequestFactoryInterface $requestFactory, + private readonly ResponseFactoryInterface $responseFactory, + private readonly ServerRequestFactoryInterface $serverRequestFactory, ) { } diff --git a/src/SDK/Common/Instrumentation/InstrumentationScope.php b/src/SDK/Common/Instrumentation/InstrumentationScope.php index f6a009624..eeb2eaf05 100644 --- a/src/SDK/Common/Instrumentation/InstrumentationScope.php +++ b/src/SDK/Common/Instrumentation/InstrumentationScope.php @@ -12,10 +12,10 @@ final class InstrumentationScope implements InstrumentationScopeInterface { public function __construct( - private string $name, - private ?string $version, - private ?string $schemaUrl, - private AttributesInterface $attributes, + private readonly string $name, + private readonly ?string $version, + private readonly ?string $schemaUrl, + private readonly AttributesInterface $attributes, ) { } diff --git a/src/SDK/Common/Instrumentation/InstrumentationScopeFactory.php b/src/SDK/Common/Instrumentation/InstrumentationScopeFactory.php index f3f73341d..e4b5fbbb0 100644 --- a/src/SDK/Common/Instrumentation/InstrumentationScopeFactory.php +++ b/src/SDK/Common/Instrumentation/InstrumentationScopeFactory.php @@ -8,7 +8,7 @@ final class InstrumentationScopeFactory implements InstrumentationScopeFactoryInterface { - public function __construct(private AttributesFactoryInterface $attributesFactory) + public function __construct(private readonly AttributesFactoryInterface $attributesFactory) { } diff --git a/src/SDK/Common/Time/StopWatch.php b/src/SDK/Common/Time/StopWatch.php index 10b967e9e..7be146679 100644 --- a/src/SDK/Common/Time/StopWatch.php +++ b/src/SDK/Common/Time/StopWatch.php @@ -12,7 +12,7 @@ final class StopWatch implements StopWatchInterface private ?int $stopTime = null; public function __construct( - private ClockInterface $clock, + private readonly ClockInterface $clock, private ?int $initialStartTime = null, ) { } diff --git a/src/SDK/Common/Time/StopWatchFactory.php b/src/SDK/Common/Time/StopWatchFactory.php index 080cdce57..6d944136a 100644 --- a/src/SDK/Common/Time/StopWatchFactory.php +++ b/src/SDK/Common/Time/StopWatchFactory.php @@ -8,11 +8,11 @@ final class StopWatchFactory implements StopWatchFactoryInterface { private static ?StopWatchInterface $default = null; - private ClockInterface $clock; + private readonly ClockInterface $clock; public function __construct( ?ClockInterface $clock = null, - private ?int $initialStartTime = null, + private readonly ?int $initialStartTime = null, ) { $this->clock = $clock ?? ClockFactory::getDefault(); } diff --git a/src/SDK/Logs/Exporter/ConsoleExporter.php b/src/SDK/Logs/Exporter/ConsoleExporter.php index 500fe6e1a..bdda9859f 100644 --- a/src/SDK/Logs/Exporter/ConsoleExporter.php +++ b/src/SDK/Logs/Exporter/ConsoleExporter.php @@ -19,7 +19,7 @@ */ class ConsoleExporter implements LogRecordExporterInterface { - public function __construct(private TransportInterface $transport) + public function __construct(private readonly TransportInterface $transport) { } diff --git a/src/SDK/Logs/Exporter/InMemoryExporter.php b/src/SDK/Logs/Exporter/InMemoryExporter.php index 871eb48a2..3ecaecd3d 100644 --- a/src/SDK/Logs/Exporter/InMemoryExporter.php +++ b/src/SDK/Logs/Exporter/InMemoryExporter.php @@ -12,11 +12,8 @@ class InMemoryExporter implements LogRecordExporterInterface { - private ArrayObject $storage; - - public function __construct(?ArrayObject $storage = null) + public function __construct(private readonly ArrayObject $storage = new ArrayObject()) { - $this->storage = $storage ?? new ArrayObject(); } /** diff --git a/src/SDK/Logs/LogRecordLimits.php b/src/SDK/Logs/LogRecordLimits.php index 70d87e13a..be80cf940 100644 --- a/src/SDK/Logs/LogRecordLimits.php +++ b/src/SDK/Logs/LogRecordLimits.php @@ -14,7 +14,7 @@ class LogRecordLimits /** * @internal Use {@see SpanLimitsBuilder} to create {@see SpanLimits} instance. */ - public function __construct(private AttributesFactoryInterface $attributesFactory) + public function __construct(private readonly AttributesFactoryInterface $attributesFactory) { } diff --git a/src/SDK/Logs/Logger.php b/src/SDK/Logs/Logger.php index ff2d40cb5..98af671b9 100644 --- a/src/SDK/Logs/Logger.php +++ b/src/SDK/Logs/Logger.php @@ -17,8 +17,8 @@ class Logger implements LoggerInterface { public function __construct( - private LoggerSharedState $loggerSharedState, - private InstrumentationScopeInterface $scope, + private readonly LoggerSharedState $loggerSharedState, + private readonly InstrumentationScopeInterface $scope, ) { } diff --git a/src/SDK/Logs/LoggerProvider.php b/src/SDK/Logs/LoggerProvider.php index f06cdbebf..707cb3319 100644 --- a/src/SDK/Logs/LoggerProvider.php +++ b/src/SDK/Logs/LoggerProvider.php @@ -13,11 +13,11 @@ class LoggerProvider implements LoggerProviderInterface { - private LoggerSharedState $loggerSharedState; + private readonly LoggerSharedState $loggerSharedState; public function __construct( LogRecordProcessorInterface $processor, - private InstrumentationScopeFactoryInterface $instrumentationScopeFactory, + private readonly InstrumentationScopeFactoryInterface $instrumentationScopeFactory, ?ResourceInfo $resource = null, ) { $this->loggerSharedState = new LoggerSharedState( diff --git a/src/SDK/Logs/LoggerProviderBuilder.php b/src/SDK/Logs/LoggerProviderBuilder.php index 456f3f804..a4ac29df5 100644 --- a/src/SDK/Logs/LoggerProviderBuilder.php +++ b/src/SDK/Logs/LoggerProviderBuilder.php @@ -12,9 +12,7 @@ class LoggerProviderBuilder { - /** - * @var array - */ + /** @var array */ private array $processors = []; private ?ResourceInfo $resource = null; diff --git a/src/SDK/Logs/LoggerSharedState.php b/src/SDK/Logs/LoggerSharedState.php index d6842fb11..cf80ccbc7 100644 --- a/src/SDK/Logs/LoggerSharedState.php +++ b/src/SDK/Logs/LoggerSharedState.php @@ -12,9 +12,9 @@ class LoggerSharedState private ?bool $shutdownResult = null; public function __construct( - private ResourceInfo $resource, - private LogRecordLimits $limits, - private LogRecordProcessorInterface $processor, + private readonly ResourceInfo $resource, + private readonly LogRecordLimits $limits, + private readonly LogRecordProcessorInterface $processor, ) { } diff --git a/src/SDK/Logs/Processor/BatchLogRecordProcessor.php b/src/SDK/Logs/Processor/BatchLogRecordProcessor.php index 6ba5f9ebf..57d0944a7 100644 --- a/src/SDK/Logs/Processor/BatchLogRecordProcessor.php +++ b/src/SDK/Logs/Processor/BatchLogRecordProcessor.php @@ -54,13 +54,13 @@ class BatchLogRecordProcessor implements LogRecordProcessorInterface private bool $closed = false; public function __construct( - private LogRecordExporterInterface $exporter, - private ClockInterface $clock, + private readonly LogRecordExporterInterface $exporter, + private readonly ClockInterface $clock, int $maxQueueSize = self::DEFAULT_MAX_QUEUE_SIZE, int $scheduledDelayMillis = self::DEFAULT_SCHEDULE_DELAY, int $exportTimeoutMillis = self::DEFAULT_EXPORT_TIMEOUT, int $maxExportBatchSize = self::DEFAULT_MAX_EXPORT_BATCH_SIZE, - private bool $autoFlush = true, + private readonly bool $autoFlush = true, ?MeterProviderInterface $meterProvider = null, ) { if ($maxQueueSize <= 0) { diff --git a/src/SDK/Logs/Processor/MultiLogRecordProcessor.php b/src/SDK/Logs/Processor/MultiLogRecordProcessor.php index 753a75df8..6a5791f19 100644 --- a/src/SDK/Logs/Processor/MultiLogRecordProcessor.php +++ b/src/SDK/Logs/Processor/MultiLogRecordProcessor.php @@ -11,7 +11,7 @@ class MultiLogRecordProcessor implements LogRecordProcessorInterface { - // @var LogRecordProcessorInterface[] + /** @var list */ private array $processors = []; public function __construct(array $processors) diff --git a/src/SDK/Logs/Processor/SimpleLogRecordProcessor.php b/src/SDK/Logs/Processor/SimpleLogRecordProcessor.php index d64340140..264a450ae 100644 --- a/src/SDK/Logs/Processor/SimpleLogRecordProcessor.php +++ b/src/SDK/Logs/Processor/SimpleLogRecordProcessor.php @@ -12,7 +12,7 @@ class SimpleLogRecordProcessor implements LogRecordProcessorInterface { - public function __construct(private LogRecordExporterInterface $exporter) + public function __construct(private readonly LogRecordExporterInterface $exporter) { } diff --git a/src/SDK/Logs/ReadableLogRecord.php b/src/SDK/Logs/ReadableLogRecord.php index 5cf8da321..f1d09e539 100644 --- a/src/SDK/Logs/ReadableLogRecord.php +++ b/src/SDK/Logs/ReadableLogRecord.php @@ -24,8 +24,8 @@ class ReadableLogRecord extends LogRecord protected SpanContextInterface $spanContext; public function __construct( - private InstrumentationScopeInterface $scope, - private LoggerSharedState $loggerSharedState, + private readonly InstrumentationScopeInterface $scope, + private readonly LoggerSharedState $loggerSharedState, LogRecord $logRecord, ) { parent::__construct($logRecord->body); diff --git a/src/SDK/Logs/SimplePsrFileLogger.php b/src/SDK/Logs/SimplePsrFileLogger.php index 9b40d1e9e..8af86b1ad 100644 --- a/src/SDK/Logs/SimplePsrFileLogger.php +++ b/src/SDK/Logs/SimplePsrFileLogger.php @@ -20,8 +20,8 @@ class SimplePsrFileLogger implements LoggerInterface private static ?array $logLevels = null; public function __construct( - private string $filename, - private string $loggerName = self::DEFAULT_LOGGER_NAME, + private readonly string $filename, + private readonly string $loggerName = self::DEFAULT_LOGGER_NAME, ) { } @@ -30,7 +30,7 @@ public function __construct( */ public function log($level, $message, array $context = []): void { - $level = strtolower($level); + $level = strtolower((string) $level); if (!in_array($level, self::getLogLevels(), true)) { throw new InvalidArgumentException( diff --git a/src/SDK/Metrics/Aggregation/ExplicitBucketHistogramAggregation.php b/src/SDK/Metrics/Aggregation/ExplicitBucketHistogramAggregation.php index 703f80191..2dacb76ac 100644 --- a/src/SDK/Metrics/Aggregation/ExplicitBucketHistogramAggregation.php +++ b/src/SDK/Metrics/Aggregation/ExplicitBucketHistogramAggregation.php @@ -22,8 +22,7 @@ final class ExplicitBucketHistogramAggregation implements AggregationInterface * @param list $boundaries strictly ascending histogram bucket boundaries */ public function __construct( - /** @readonly */ - public array $boundaries, + public readonly array $boundaries, ) { } @@ -138,23 +137,13 @@ public function toData( ); } - /** - * @param float|int $left - * @param float|int $right - * @return float|int - */ - private static function min($left, $right) + private static function min(float|int $left, float|int $right): float|int { /** @noinspection PhpConditionAlreadyCheckedInspection */ return $left <= $right ? $left : ($right <= $left ? $right : NAN); } - /** - * @param float|int $left - * @param float|int $right - * @return float|int - */ - private static function max($left, $right) + private static function max(float|int $left, float|int $right): float|int { /** @noinspection PhpConditionAlreadyCheckedInspection */ return $left >= $right ? $left : ($right >= $left ? $right : NAN); diff --git a/src/SDK/Metrics/Aggregation/SumAggregation.php b/src/SDK/Metrics/Aggregation/SumAggregation.php index dd4ff5d3a..5947f6e9f 100644 --- a/src/SDK/Metrics/Aggregation/SumAggregation.php +++ b/src/SDK/Metrics/Aggregation/SumAggregation.php @@ -14,7 +14,7 @@ */ final class SumAggregation implements AggregationInterface { - public function __construct(private bool $monotonic = false) + public function __construct(private readonly bool $monotonic = false) { } diff --git a/src/SDK/Metrics/AttributeProcessor/FilteredAttributeProcessor.php b/src/SDK/Metrics/AttributeProcessor/FilteredAttributeProcessor.php index 57f0c33a6..00b2b460a 100644 --- a/src/SDK/Metrics/AttributeProcessor/FilteredAttributeProcessor.php +++ b/src/SDK/Metrics/AttributeProcessor/FilteredAttributeProcessor.php @@ -14,7 +14,7 @@ */ final class FilteredAttributeProcessor implements AttributeProcessorInterface { - public function __construct(private array $attributeKeys) + public function __construct(private readonly array $attributeKeys) { } diff --git a/src/SDK/Metrics/Data/Exemplar.php b/src/SDK/Metrics/Data/Exemplar.php index 5d6be7380..245da347e 100644 --- a/src/SDK/Metrics/Data/Exemplar.php +++ b/src/SDK/Metrics/Data/Exemplar.php @@ -9,17 +9,12 @@ final class Exemplar { public function __construct( - private int|string $index, - /** @readonly */ - public float|int $value, - /** @readonly */ - public int $timestamp, - /** @readonly */ - public AttributesInterface $attributes, - /** @readonly */ - public ?string $traceId, - /** @readonly */ - public ?string $spanId, + private readonly int|string $index, + public readonly float|int $value, + public readonly int $timestamp, + public readonly AttributesInterface $attributes, + public readonly ?string $traceId, + public readonly ?string $spanId, ) { } diff --git a/src/SDK/Metrics/Data/Gauge.php b/src/SDK/Metrics/Data/Gauge.php index 732b0387d..f8bf9caa5 100644 --- a/src/SDK/Metrics/Data/Gauge.php +++ b/src/SDK/Metrics/Data/Gauge.php @@ -11,8 +11,7 @@ final class Gauge implements DataInterface * @param iterable $dataPoints */ public function __construct( - /** @readonly */ - public iterable $dataPoints, + public readonly iterable $dataPoints, ) { } } diff --git a/src/SDK/Metrics/Data/Histogram.php b/src/SDK/Metrics/Data/Histogram.php index 1f19254a3..49fdb7802 100644 --- a/src/SDK/Metrics/Data/Histogram.php +++ b/src/SDK/Metrics/Data/Histogram.php @@ -10,10 +10,8 @@ final class Histogram implements DataInterface * @param iterable $dataPoints */ public function __construct( - /** @readonly */ - public iterable $dataPoints, - /** @readonly */ - public string|Temporality $temporality, + public readonly iterable $dataPoints, + public readonly string|Temporality $temporality, ) { } } diff --git a/src/SDK/Metrics/Data/HistogramDataPoint.php b/src/SDK/Metrics/Data/HistogramDataPoint.php index 0af01746c..e429944b9 100644 --- a/src/SDK/Metrics/Data/HistogramDataPoint.php +++ b/src/SDK/Metrics/Data/HistogramDataPoint.php @@ -13,26 +13,16 @@ final class HistogramDataPoint * @param list $explicitBounds */ public function __construct( - /** @readonly */ - public int $count, - /** @readonly */ - public float|int $sum, - /** @readonly */ - public float|int $min, - /** @readonly */ - public float|int $max, - /** @readonly */ - public array $bucketCounts, - /** @readonly */ - public array $explicitBounds, - /** @readonly */ - public AttributesInterface $attributes, - /** @readonly */ - public int $startTimestamp, - /** @readonly */ - public int $timestamp, - /** @readonly */ - public iterable $exemplars = [], + public readonly int $count, + public readonly float|int $sum, + public readonly float|int $min, + public readonly float|int $max, + public readonly array $bucketCounts, + public readonly array $explicitBounds, + public readonly AttributesInterface $attributes, + public readonly int $startTimestamp, + public readonly int $timestamp, + public readonly iterable $exemplars = [], ) { } } diff --git a/src/SDK/Metrics/Data/Metric.php b/src/SDK/Metrics/Data/Metric.php index 3963c11a4..bfa41204a 100644 --- a/src/SDK/Metrics/Data/Metric.php +++ b/src/SDK/Metrics/Data/Metric.php @@ -10,18 +10,12 @@ final class Metric { public function __construct( - /** @readonly */ - public InstrumentationScopeInterface $instrumentationScope, - /** @readonly */ - public ResourceInfo $resource, - /** @readonly */ - public string $name, - /** @readonly */ - public ?string $unit, - /** @readonly */ - public ?string $description, - /** @readonly */ - public DataInterface $data, + public readonly InstrumentationScopeInterface $instrumentationScope, + public readonly ResourceInfo $resource, + public readonly string $name, + public readonly ?string $unit, + public readonly ?string $description, + public readonly DataInterface $data, ) { } } diff --git a/src/SDK/Metrics/Data/NumberDataPoint.php b/src/SDK/Metrics/Data/NumberDataPoint.php index 7159fd600..6ae17cb33 100644 --- a/src/SDK/Metrics/Data/NumberDataPoint.php +++ b/src/SDK/Metrics/Data/NumberDataPoint.php @@ -9,16 +9,11 @@ final class NumberDataPoint { public function __construct( - /** @readonly */ - public float|int $value, - /** @readonly */ - public AttributesInterface $attributes, - /** @readonly */ - public int $startTimestamp, - /** @readonly */ - public int $timestamp, - /** @readonly */ - public iterable $exemplars = [], + public readonly float|int $value, + public readonly AttributesInterface $attributes, + public readonly int $startTimestamp, + public readonly int $timestamp, + public readonly iterable $exemplars = [], ) { } } diff --git a/src/SDK/Metrics/Data/Sum.php b/src/SDK/Metrics/Data/Sum.php index 56cdf91a4..f4e32ea1d 100644 --- a/src/SDK/Metrics/Data/Sum.php +++ b/src/SDK/Metrics/Data/Sum.php @@ -10,12 +10,9 @@ final class Sum implements DataInterface * @param iterable $dataPoints */ public function __construct( - /** @readonly */ - public iterable $dataPoints, - /** @readonly */ - public string|Temporality $temporality, - /** @readonly */ - public bool $monotonic, + public readonly iterable $dataPoints, + public readonly string|Temporality $temporality, + public readonly bool $monotonic, ) { } } diff --git a/src/SDK/Metrics/Exemplar/BucketEntry.php b/src/SDK/Metrics/Exemplar/BucketEntry.php index 3a50430ed..75a099b03 100644 --- a/src/SDK/Metrics/Exemplar/BucketEntry.php +++ b/src/SDK/Metrics/Exemplar/BucketEntry.php @@ -11,14 +11,8 @@ */ final class BucketEntry { - /** - * @var int|string - */ - public $index; - /** - * @var float|int - */ - public $value; + public int|string $index; + public float|int $value; public int $timestamp; public AttributesInterface $attributes; public ?string $traceId = null; diff --git a/src/SDK/Metrics/Exemplar/BucketStorage.php b/src/SDK/Metrics/Exemplar/BucketStorage.php index 574ce92af..cd3b0808d 100644 --- a/src/SDK/Metrics/Exemplar/BucketStorage.php +++ b/src/SDK/Metrics/Exemplar/BucketStorage.php @@ -26,11 +26,7 @@ public function __construct(int $size = 0) $this->buckets = array_fill(0, $size, null); } - /** - * @param int|string $index - * @param float|int $value - */ - public function store(int $bucket, $index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + public function store(int $bucket, int|string $index, float|int $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void { assert($bucket <= count($this->buckets)); diff --git a/src/SDK/Metrics/Exemplar/ExemplarFilterInterface.php b/src/SDK/Metrics/Exemplar/ExemplarFilterInterface.php index 1d5dec7b8..5aebcf67c 100644 --- a/src/SDK/Metrics/Exemplar/ExemplarFilterInterface.php +++ b/src/SDK/Metrics/Exemplar/ExemplarFilterInterface.php @@ -13,8 +13,5 @@ */ interface ExemplarFilterInterface { - /** - * @param float|int $value - */ - public function accepts($value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): bool; + public function accepts(float|int $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): bool; } diff --git a/src/SDK/Metrics/Exemplar/ExemplarReservoirInterface.php b/src/SDK/Metrics/Exemplar/ExemplarReservoirInterface.php index 70648b919..fe59c1ae4 100644 --- a/src/SDK/Metrics/Exemplar/ExemplarReservoirInterface.php +++ b/src/SDK/Metrics/Exemplar/ExemplarReservoirInterface.php @@ -10,11 +10,7 @@ interface ExemplarReservoirInterface { - /** - * @param int|string $index - * @param float|int $value - */ - public function offer($index, $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void; + public function offer(int|string $index, float|int $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void; /** * @param array $dataPointAttributes diff --git a/src/SDK/Metrics/Exemplar/FilteredReservoir.php b/src/SDK/Metrics/Exemplar/FilteredReservoir.php index 5ef1baaac..d89feb8d2 100644 --- a/src/SDK/Metrics/Exemplar/FilteredReservoir.php +++ b/src/SDK/Metrics/Exemplar/FilteredReservoir.php @@ -14,8 +14,8 @@ final class FilteredReservoir implements ExemplarReservoirInterface { public function __construct( - private ExemplarReservoirInterface $reservoir, - private ExemplarFilterInterface $filter, + private readonly ExemplarReservoirInterface $reservoir, + private readonly ExemplarFilterInterface $filter, ) { } diff --git a/src/SDK/Metrics/Exemplar/FixedSizeReservoir.php b/src/SDK/Metrics/Exemplar/FixedSizeReservoir.php index 479292a4c..e02efbe7d 100644 --- a/src/SDK/Metrics/Exemplar/FixedSizeReservoir.php +++ b/src/SDK/Metrics/Exemplar/FixedSizeReservoir.php @@ -10,8 +10,8 @@ final class FixedSizeReservoir implements ExemplarReservoirInterface { - private BucketStorage $storage; - private int $size; + private readonly BucketStorage $storage; + private readonly int $size; private int $measurements = 0; public function __construct(int $size = 4) diff --git a/src/SDK/Metrics/Exemplar/HistogramBucketReservoir.php b/src/SDK/Metrics/Exemplar/HistogramBucketReservoir.php index b56a1b2be..a15d41081 100644 --- a/src/SDK/Metrics/Exemplar/HistogramBucketReservoir.php +++ b/src/SDK/Metrics/Exemplar/HistogramBucketReservoir.php @@ -10,7 +10,7 @@ final class HistogramBucketReservoir implements ExemplarReservoirInterface { - private BucketStorage $storage; + private readonly BucketStorage $storage; /** * @var list */ diff --git a/src/SDK/Metrics/Instrument.php b/src/SDK/Metrics/Instrument.php index 3a0019f39..8d9a5b363 100644 --- a/src/SDK/Metrics/Instrument.php +++ b/src/SDK/Metrics/Instrument.php @@ -7,16 +7,11 @@ final class Instrument { public function __construct( - /** @readonly */ - public string|InstrumentType $type, - /** @readonly */ - public string $name, - /** @readonly */ - public ?string $unit, - /** @readonly */ - public ?string $description, - /** @readonly */ - public array $advisory = [], + public readonly string|InstrumentType $type, + public readonly string $name, + public readonly ?string $unit, + public readonly ?string $description, + public readonly array $advisory = [], ) { } } diff --git a/src/SDK/Metrics/Meter.php b/src/SDK/Metrics/Meter.php index 5dcf0ff1a..b54b488dc 100644 --- a/src/SDK/Metrics/Meter.php +++ b/src/SDK/Metrics/Meter.php @@ -44,18 +44,18 @@ final class Meter implements MeterInterface * @param ArrayAccess $destructors */ public function __construct( - private MetricFactoryInterface $metricFactory, - private ResourceInfo $resource, - private ClockInterface $clock, - private StalenessHandlerFactoryInterface $stalenessHandlerFactory, - private iterable $metricRegistries, - private ViewRegistryInterface $viewRegistry, - private ?ExemplarFilterInterface $exemplarFilter, - private MeterInstruments $instruments, - private InstrumentationScopeInterface $instrumentationScope, - private MetricRegistryInterface $registry, - private MetricWriterInterface $writer, - private ArrayAccess $destructors, + private readonly MetricFactoryInterface $metricFactory, + private readonly ResourceInfo $resource, + private readonly ClockInterface $clock, + private readonly StalenessHandlerFactoryInterface $stalenessHandlerFactory, + private readonly iterable $metricRegistries, + private readonly ViewRegistryInterface $viewRegistry, + private readonly ?ExemplarFilterInterface $exemplarFilter, + private readonly MeterInstruments $instruments, + private readonly InstrumentationScopeInterface $instrumentationScope, + private readonly MetricRegistryInterface $registry, + private readonly MetricWriterInterface $writer, + private readonly ArrayAccess $destructors, ) { } diff --git a/src/SDK/Metrics/MeterProvider.php b/src/SDK/Metrics/MeterProvider.php index 942d07570..db3d19e04 100644 --- a/src/SDK/Metrics/MeterProvider.php +++ b/src/SDK/Metrics/MeterProvider.php @@ -22,11 +22,11 @@ final class MeterProvider implements MeterProviderInterface { - private MetricFactoryInterface $metricFactory; - private MeterInstruments $instruments; - private MetricRegistryInterface $registry; - private MetricWriterInterface $writer; - private ArrayAccess $destructors; + private readonly MetricFactoryInterface $metricFactory; + private readonly MeterInstruments $instruments; + private readonly MetricRegistryInterface $registry; + private readonly MetricWriterInterface $writer; + private readonly ArrayAccess $destructors; private bool $closed = false; @@ -35,14 +35,14 @@ final class MeterProvider implements MeterProviderInterface */ public function __construct( ?ContextStorageInterface $contextStorage, - private ResourceInfo $resource, - private ClockInterface $clock, + private readonly ResourceInfo $resource, + private readonly ClockInterface $clock, AttributesFactoryInterface $attributesFactory, - private InstrumentationScopeFactoryInterface $instrumentationScopeFactory, - private iterable $metricReaders, - private ViewRegistryInterface $viewRegistry, - private ?ExemplarFilterInterface $exemplarFilter, - private StalenessHandlerFactoryInterface $stalenessHandlerFactory, + private readonly InstrumentationScopeFactoryInterface $instrumentationScopeFactory, + private readonly iterable $metricReaders, + private readonly ViewRegistryInterface $viewRegistry, + private readonly ?ExemplarFilterInterface $exemplarFilter, + private readonly StalenessHandlerFactoryInterface $stalenessHandlerFactory, MetricFactoryInterface $metricFactory = null, ) { $this->metricFactory = $metricFactory ?? new StreamFactory(); diff --git a/src/SDK/Metrics/MetricExporter/ConsoleMetricExporter.php b/src/SDK/Metrics/MetricExporter/ConsoleMetricExporter.php index 0a2493a05..8b75771d2 100644 --- a/src/SDK/Metrics/MetricExporter/ConsoleMetricExporter.php +++ b/src/SDK/Metrics/MetricExporter/ConsoleMetricExporter.php @@ -18,16 +18,13 @@ */ class ConsoleMetricExporter implements PushMetricExporterInterface, AggregationTemporalitySelectorInterface { - /** - * @param string|Temporality|null $temporality - */ - public function __construct(private $temporality = null) + public function __construct(private readonly Temporality|string|null $temporality = null) { } /** * @inheritDoc */ - public function temporality(MetricMetadataInterface $metric) + public function temporality(MetricMetadataInterface $metric): Temporality|string|null { return $this->temporality ?? $metric->temporality(); } diff --git a/src/SDK/Metrics/MetricExporter/InMemoryExporter.php b/src/SDK/Metrics/MetricExporter/InMemoryExporter.php index ce250cd17..e0d7da4ec 100644 --- a/src/SDK/Metrics/MetricExporter/InMemoryExporter.php +++ b/src/SDK/Metrics/MetricExporter/InMemoryExporter.php @@ -23,7 +23,7 @@ final class InMemoryExporter implements MetricExporterInterface, AggregationTemp private bool $closed = false; - public function __construct(private string|Temporality|null $temporality = null) + public function __construct(private readonly string|Temporality|null $temporality = null) { } diff --git a/src/SDK/Metrics/MetricFactory/StreamMetricSource.php b/src/SDK/Metrics/MetricFactory/StreamMetricSource.php index d8bb9a8b4..5b105a5a5 100644 --- a/src/SDK/Metrics/MetricFactory/StreamMetricSource.php +++ b/src/SDK/Metrics/MetricFactory/StreamMetricSource.php @@ -13,8 +13,8 @@ final class StreamMetricSource implements MetricSourceInterface { public function __construct( - private StreamMetricSourceProvider $provider, - private int $reader, + private readonly StreamMetricSourceProvider $provider, + private readonly int $reader, ) { } diff --git a/src/SDK/Metrics/MetricFactory/StreamMetricSourceProvider.php b/src/SDK/Metrics/MetricFactory/StreamMetricSourceProvider.php index 5d20be5ab..ec42fc416 100644 --- a/src/SDK/Metrics/MetricFactory/StreamMetricSourceProvider.php +++ b/src/SDK/Metrics/MetricFactory/StreamMetricSourceProvider.php @@ -20,20 +20,13 @@ final class StreamMetricSourceProvider implements MetricSourceProviderInterface, MetricMetadataInterface { public function __construct( - /** @readonly */ - public ViewProjection $view, - /** @readonly */ - public Instrument $instrument, - /** @readonly */ - public InstrumentationScopeInterface $instrumentationLibrary, - /** @readonly */ - public ResourceInfo $resource, - /** @readonly */ - public MetricStreamInterface $stream, - /** @readonly */ - public MetricCollectorInterface $metricCollector, - /** @readonly */ - public int $streamId, + public readonly ViewProjection $view, + public readonly Instrument $instrument, + public readonly InstrumentationScopeInterface $instrumentationLibrary, + public readonly ResourceInfo $resource, + public readonly MetricStreamInterface $stream, + public readonly MetricCollectorInterface $metricCollector, + public readonly int $streamId, ) { } diff --git a/src/SDK/Metrics/MetricReader/ExportingReader.php b/src/SDK/Metrics/MetricReader/ExportingReader.php index 49b0b0f00..b7eef1d7b 100644 --- a/src/SDK/Metrics/MetricReader/ExportingReader.php +++ b/src/SDK/Metrics/MetricReader/ExportingReader.php @@ -34,7 +34,7 @@ final class ExportingReader implements MetricReaderInterface, MetricSourceRegist private bool $closed = false; - public function __construct(private MetricExporterInterface $exporter) + public function __construct(private readonly MetricExporterInterface $exporter) { } diff --git a/src/SDK/Metrics/MetricRegistration/MultiRegistryRegistration.php b/src/SDK/Metrics/MetricRegistration/MultiRegistryRegistration.php index 8ec89b1ad..47509c03c 100644 --- a/src/SDK/Metrics/MetricRegistration/MultiRegistryRegistration.php +++ b/src/SDK/Metrics/MetricRegistration/MultiRegistryRegistration.php @@ -19,8 +19,8 @@ final class MultiRegistryRegistration implements MetricRegistrationInterface * @param iterable $registries */ public function __construct( - private iterable $registries, - private StalenessHandlerInterface $stalenessHandler, + private readonly iterable $registries, + private readonly StalenessHandlerInterface $stalenessHandler, ) { } diff --git a/src/SDK/Metrics/MetricRegistration/RegistryRegistration.php b/src/SDK/Metrics/MetricRegistration/RegistryRegistration.php index 58e06867e..c3bfed02c 100644 --- a/src/SDK/Metrics/MetricRegistration/RegistryRegistration.php +++ b/src/SDK/Metrics/MetricRegistration/RegistryRegistration.php @@ -16,8 +16,8 @@ final class RegistryRegistration implements MetricRegistrationInterface { public function __construct( - private MetricSourceRegistryInterface $registry, - private StalenessHandlerInterface $stalenessHandler, + private readonly MetricSourceRegistryInterface $registry, + private readonly StalenessHandlerInterface $stalenessHandler, ) { } diff --git a/src/SDK/Metrics/MetricRegistry/MetricRegistry.php b/src/SDK/Metrics/MetricRegistry/MetricRegistry.php index 9b44a5dd1..c5da81e26 100644 --- a/src/SDK/Metrics/MetricRegistry/MetricRegistry.php +++ b/src/SDK/Metrics/MetricRegistry/MetricRegistry.php @@ -40,9 +40,9 @@ final class MetricRegistry implements MetricRegistryInterface, MetricWriterInter private array $asynchronousCallbackArguments = []; public function __construct( - private ?ContextStorageInterface $contextStorage, - private AttributesFactoryInterface $attributesFactory, - private ClockInterface $clock, + private readonly ?ContextStorageInterface $contextStorage, + private readonly AttributesFactoryInterface $attributesFactory, + private readonly ClockInterface $clock, ) { } diff --git a/src/SDK/Metrics/MetricRegistry/MultiObserver.php b/src/SDK/Metrics/MetricRegistry/MultiObserver.php index 6c474cacd..96155a5b8 100644 --- a/src/SDK/Metrics/MetricRegistry/MultiObserver.php +++ b/src/SDK/Metrics/MetricRegistry/MultiObserver.php @@ -18,8 +18,8 @@ final class MultiObserver implements ObserverInterface public array $writers = []; public function __construct( - private AttributesFactoryInterface $attributesFactory, - private int $timestamp, + private readonly AttributesFactoryInterface $attributesFactory, + private readonly int $timestamp, ) { } diff --git a/src/SDK/Metrics/ObservableCallback.php b/src/SDK/Metrics/ObservableCallback.php index 260405f75..b4852e98c 100644 --- a/src/SDK/Metrics/ObservableCallback.php +++ b/src/SDK/Metrics/ObservableCallback.php @@ -14,10 +14,10 @@ final class ObservableCallback implements ObservableCallbackInterface { public function __construct( - private MetricWriterInterface $writer, - private ReferenceCounterInterface $referenceCounter, + private readonly MetricWriterInterface $writer, + private readonly ReferenceCounterInterface $referenceCounter, private ?int $callbackId, - private ?ObservableCallbackDestructor $callbackDestructor, + private readonly ?ObservableCallbackDestructor $callbackDestructor, private ?object $target, ) { } diff --git a/src/SDK/Metrics/ObservableCallbackDestructor.php b/src/SDK/Metrics/ObservableCallbackDestructor.php index 49cbe6f11..101df361c 100644 --- a/src/SDK/Metrics/ObservableCallbackDestructor.php +++ b/src/SDK/Metrics/ObservableCallbackDestructor.php @@ -20,7 +20,7 @@ final class ObservableCallbackDestructor */ public function __construct( public ArrayAccess $destructors, - private MetricWriterInterface $writer, + private readonly MetricWriterInterface $writer, ) { } diff --git a/src/SDK/Metrics/StalenessHandler/DelayedStalenessHandler.php b/src/SDK/Metrics/StalenessHandler/DelayedStalenessHandler.php index a3fab42fa..19b26e4b0 100644 --- a/src/SDK/Metrics/StalenessHandler/DelayedStalenessHandler.php +++ b/src/SDK/Metrics/StalenessHandler/DelayedStalenessHandler.php @@ -19,8 +19,8 @@ final class DelayedStalenessHandler implements StalenessHandlerInterface, Refere private int $count = 0; public function __construct( - private Closure $stale, - private Closure $freshen, + private readonly Closure $stale, + private readonly Closure $freshen, ) { } diff --git a/src/SDK/Metrics/StalenessHandler/DelayedStalenessHandlerFactory.php b/src/SDK/Metrics/StalenessHandler/DelayedStalenessHandlerFactory.php index 4e79f696e..08e9b181c 100644 --- a/src/SDK/Metrics/StalenessHandler/DelayedStalenessHandlerFactory.php +++ b/src/SDK/Metrics/StalenessHandler/DelayedStalenessHandlerFactory.php @@ -6,16 +6,17 @@ use Closure; use OpenTelemetry\SDK\Common\Time\ClockInterface; +use OpenTelemetry\SDK\Metrics\ReferenceCounterInterface; use OpenTelemetry\SDK\Metrics\StalenessHandlerFactoryInterface; use OpenTelemetry\SDK\Metrics\StalenessHandlerInterface; use WeakMap; final class DelayedStalenessHandlerFactory implements StalenessHandlerFactoryInterface { - private int $nanoDelay; + private readonly int $nanoDelay; - private Closure $stale; - private Closure $freshen; + private readonly Closure $stale; + private readonly Closure $freshen; /** @var WeakMap */ private WeakMap $staleHandlers; @@ -25,7 +26,7 @@ final class DelayedStalenessHandlerFactory implements StalenessHandlerFactoryInt * @psalm-suppress PropertyTypeCoercion */ public function __construct( - private ClockInterface $clock, + private readonly ClockInterface $clock, float $delay, ) { $this->nanoDelay = (int) ($delay * 1e9); @@ -40,7 +41,7 @@ public function __construct( $this->staleHandlers = new WeakMap(); } - public function create(): StalenessHandlerInterface + public function create(): ReferenceCounterInterface&StalenessHandlerInterface { $this->triggerStaleHandlers(); diff --git a/src/SDK/Metrics/StalenessHandler/ImmediateStalenessHandlerFactory.php b/src/SDK/Metrics/StalenessHandler/ImmediateStalenessHandlerFactory.php index 899615dea..dec5ed6c8 100644 --- a/src/SDK/Metrics/StalenessHandler/ImmediateStalenessHandlerFactory.php +++ b/src/SDK/Metrics/StalenessHandler/ImmediateStalenessHandlerFactory.php @@ -4,12 +4,13 @@ namespace OpenTelemetry\SDK\Metrics\StalenessHandler; +use OpenTelemetry\SDK\Metrics\ReferenceCounterInterface; use OpenTelemetry\SDK\Metrics\StalenessHandlerFactoryInterface; use OpenTelemetry\SDK\Metrics\StalenessHandlerInterface; final class ImmediateStalenessHandlerFactory implements StalenessHandlerFactoryInterface { - public function create(): StalenessHandlerInterface + public function create(): ReferenceCounterInterface&StalenessHandlerInterface { return new ImmediateStalenessHandler(); } diff --git a/src/SDK/Metrics/StalenessHandler/MultiReferenceCounter.php b/src/SDK/Metrics/StalenessHandler/MultiReferenceCounter.php index f5ae90f1b..a3b17b6d6 100644 --- a/src/SDK/Metrics/StalenessHandler/MultiReferenceCounter.php +++ b/src/SDK/Metrics/StalenessHandler/MultiReferenceCounter.php @@ -14,7 +14,7 @@ final class MultiReferenceCounter implements ReferenceCounterInterface /** * @param list $referenceCounters */ - public function __construct(private array $referenceCounters) + public function __construct(private readonly array $referenceCounters) { } diff --git a/src/SDK/Metrics/StalenessHandler/NoopStalenessHandlerFactory.php b/src/SDK/Metrics/StalenessHandler/NoopStalenessHandlerFactory.php index 07f34e3b0..03e5b7e73 100644 --- a/src/SDK/Metrics/StalenessHandler/NoopStalenessHandlerFactory.php +++ b/src/SDK/Metrics/StalenessHandler/NoopStalenessHandlerFactory.php @@ -4,12 +4,13 @@ namespace OpenTelemetry\SDK\Metrics\StalenessHandler; +use OpenTelemetry\SDK\Metrics\ReferenceCounterInterface; use OpenTelemetry\SDK\Metrics\StalenessHandlerFactoryInterface; use OpenTelemetry\SDK\Metrics\StalenessHandlerInterface; final class NoopStalenessHandlerFactory implements StalenessHandlerFactoryInterface { - public function create(): StalenessHandlerInterface + public function create(): ReferenceCounterInterface&StalenessHandlerInterface { static $instance; diff --git a/src/SDK/Metrics/StalenessHandlerFactoryInterface.php b/src/SDK/Metrics/StalenessHandlerFactoryInterface.php index e22385420..6e623ee69 100644 --- a/src/SDK/Metrics/StalenessHandlerFactoryInterface.php +++ b/src/SDK/Metrics/StalenessHandlerFactoryInterface.php @@ -6,8 +6,5 @@ interface StalenessHandlerFactoryInterface { - /** - * @return StalenessHandlerInterface&ReferenceCounterInterface - */ - public function create(): StalenessHandlerInterface; + public function create(): StalenessHandlerInterface&ReferenceCounterInterface; } diff --git a/src/SDK/Metrics/Stream/AsynchronousMetricStream.php b/src/SDK/Metrics/Stream/AsynchronousMetricStream.php index 7d812925e..a6a8930fc 100644 --- a/src/SDK/Metrics/Stream/AsynchronousMetricStream.php +++ b/src/SDK/Metrics/Stream/AsynchronousMetricStream.php @@ -22,13 +22,13 @@ final class AsynchronousMetricStream implements MetricStreamInterface private array $lastReads = []; public function __construct( - private AggregationInterface $aggregation, - private int $startTimestamp, + private readonly AggregationInterface $aggregation, + private readonly int $startTimestamp, ) { $this->metric = new Metric([], [], $startTimestamp); } - public function temporality() + public function temporality(): Temporality|string { return Temporality::CUMULATIVE; } diff --git a/src/SDK/Metrics/Stream/DeltaStorage.php b/src/SDK/Metrics/Stream/DeltaStorage.php index 005d4e0ff..066d2d948 100644 --- a/src/SDK/Metrics/Stream/DeltaStorage.php +++ b/src/SDK/Metrics/Stream/DeltaStorage.php @@ -16,7 +16,7 @@ final class DeltaStorage { private Delta $head; - public function __construct(private AggregationInterface $aggregation) + public function __construct(private readonly AggregationInterface $aggregation) { $this->head = new Delta(new Metric([], [], 0), 0); diff --git a/src/SDK/Metrics/Stream/MetricAggregator.php b/src/SDK/Metrics/Stream/MetricAggregator.php index 17fd69712..d381a94f8 100644 --- a/src/SDK/Metrics/Stream/MetricAggregator.php +++ b/src/SDK/Metrics/Stream/MetricAggregator.php @@ -21,16 +21,13 @@ final class MetricAggregator implements MetricAggregatorInterface private array $summaries = []; public function __construct( - private ?AttributeProcessorInterface $attributeProcessor, - private AggregationInterface $aggregation, - private ?ExemplarReservoirInterface $exemplarReservoir = null, + private readonly ?AttributeProcessorInterface $attributeProcessor, + private readonly AggregationInterface $aggregation, + private readonly ?ExemplarReservoirInterface $exemplarReservoir = null, ) { } - /** - * @param float|int $value - */ - public function record($value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void + public function record(float|int $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void { $filteredAttributes = $this->attributeProcessor !== null ? $this->attributeProcessor->process($attributes, $context) diff --git a/src/SDK/Metrics/Stream/MetricAggregatorFactory.php b/src/SDK/Metrics/Stream/MetricAggregatorFactory.php index 44d8fddd0..9012fda00 100644 --- a/src/SDK/Metrics/Stream/MetricAggregatorFactory.php +++ b/src/SDK/Metrics/Stream/MetricAggregatorFactory.php @@ -13,8 +13,8 @@ final class MetricAggregatorFactory implements MetricAggregatorFactoryInterface { public function __construct( - private ?AttributeProcessorInterface $attributeProcessor, - private AggregationInterface $aggregation, + private readonly ?AttributeProcessorInterface $attributeProcessor, + private readonly AggregationInterface $aggregation, ) { } diff --git a/src/SDK/Metrics/Stream/SynchronousMetricStream.php b/src/SDK/Metrics/Stream/SynchronousMetricStream.php index 1a7c49783..80bbdc7dc 100644 --- a/src/SDK/Metrics/Stream/SynchronousMetricStream.php +++ b/src/SDK/Metrics/Stream/SynchronousMetricStream.php @@ -24,18 +24,21 @@ */ final class SynchronousMetricStream implements MetricStreamInterface { - private DeltaStorage $delta; + private readonly DeltaStorage $delta; private int|GMP $readers = 0; private int|GMP $cumulative = 0; + /** + * @todo rector mistakenly makes $timestamp readonly, which conflicts with `self::push`. disabled in rector.php + */ public function __construct( - private AggregationInterface $aggregation, + private readonly AggregationInterface $aggregation, private int $timestamp, ) { $this->delta = new DeltaStorage($this->aggregation); } - public function temporality() + public function temporality(): Temporality|string { return Temporality::DELTA; } diff --git a/src/SDK/Metrics/Stream/WritableMetricStreamInterface.php b/src/SDK/Metrics/Stream/WritableMetricStreamInterface.php index 9fd425a44..5a439ab40 100644 --- a/src/SDK/Metrics/Stream/WritableMetricStreamInterface.php +++ b/src/SDK/Metrics/Stream/WritableMetricStreamInterface.php @@ -12,8 +12,5 @@ */ interface WritableMetricStreamInterface { - /** - * @param float|int $value - */ - public function record($value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void; + public function record(float|int $value, AttributesInterface $attributes, ContextInterface $context, int $timestamp): void; } diff --git a/src/SDK/Metrics/View/SelectionCriteria/AllCriteria.php b/src/SDK/Metrics/View/SelectionCriteria/AllCriteria.php index 11bada130..138e2a5c9 100644 --- a/src/SDK/Metrics/View/SelectionCriteria/AllCriteria.php +++ b/src/SDK/Metrics/View/SelectionCriteria/AllCriteria.php @@ -13,7 +13,7 @@ final class AllCriteria implements SelectionCriteriaInterface /** * @param iterable $criteria */ - public function __construct(private iterable $criteria) + public function __construct(private readonly iterable $criteria) { } diff --git a/src/SDK/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php b/src/SDK/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php index dbba6a068..104771efe 100644 --- a/src/SDK/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php +++ b/src/SDK/Metrics/View/SelectionCriteria/InstrumentNameCriteria.php @@ -14,7 +14,7 @@ final class InstrumentNameCriteria implements SelectionCriteriaInterface { - private string $pattern; + private readonly string $pattern; /** * @param non-empty-string $name diff --git a/src/SDK/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php b/src/SDK/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php index 46a88def0..35868e8a9 100644 --- a/src/SDK/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php +++ b/src/SDK/Metrics/View/SelectionCriteria/InstrumentTypeCriteria.php @@ -12,7 +12,7 @@ final class InstrumentTypeCriteria implements SelectionCriteriaInterface { - private array $instrumentTypes; + private readonly array $instrumentTypes; /** * @param string|InstrumentType|string[]|InstrumentType[] $instrumentType diff --git a/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php b/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php index 7823e6eb5..006b6154f 100644 --- a/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php +++ b/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeNameCriteria.php @@ -10,7 +10,7 @@ final class InstrumentationScopeNameCriteria implements SelectionCriteriaInterface { - public function __construct(private string $name) + public function __construct(private readonly string $name) { } diff --git a/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php b/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php index 08cb28668..d6bb8a873 100644 --- a/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php +++ b/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeSchemaUrlCriteria.php @@ -10,7 +10,7 @@ final class InstrumentationScopeSchemaUrlCriteria implements SelectionCriteriaInterface { - public function __construct(private ?string $schemaUrl) + public function __construct(private readonly ?string $schemaUrl) { } diff --git a/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php b/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php index d9e399d2d..e61ffd177 100644 --- a/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php +++ b/src/SDK/Metrics/View/SelectionCriteria/InstrumentationScopeVersionCriteria.php @@ -10,7 +10,7 @@ final class InstrumentationScopeVersionCriteria implements SelectionCriteriaInterface { - public function __construct(private ?string $version) + public function __construct(private readonly ?string $version) { } diff --git a/src/SDK/Metrics/View/ViewTemplate.php b/src/SDK/Metrics/View/ViewTemplate.php index 302ed83ae..d1ebf09b4 100644 --- a/src/SDK/Metrics/View/ViewTemplate.php +++ b/src/SDK/Metrics/View/ViewTemplate.php @@ -12,9 +12,7 @@ final class ViewTemplate { private ?string $name = null; private ?string $description = null; - /** - * @var list - */ + /** @var list */ private ?array $attributeKeys = null; private ?AggregationInterface $aggregation = null; diff --git a/src/SDK/Metrics/ViewProjection.php b/src/SDK/Metrics/ViewProjection.php index 9d8e2001a..c9c0101bb 100644 --- a/src/SDK/Metrics/ViewProjection.php +++ b/src/SDK/Metrics/ViewProjection.php @@ -10,16 +10,11 @@ final class ViewProjection * @param list|null $attributeKeys */ public function __construct( - /** @readonly */ - public string $name, - /** @readonly */ - public ?string $unit, - /** @readonly */ - public ?string $description, - /** @readonly */ - public ?array $attributeKeys, - /** @readonly */ - public ?AggregationInterface $aggregation, + public readonly string $name, + public readonly ?string $unit, + public readonly ?string $description, + public readonly ?array $attributeKeys, + public readonly ?AggregationInterface $aggregation, ) { } } diff --git a/src/SDK/Resource/Detectors/Composite.php b/src/SDK/Resource/Detectors/Composite.php index d3edd2e7b..7515e5dfd 100644 --- a/src/SDK/Resource/Detectors/Composite.php +++ b/src/SDK/Resource/Detectors/Composite.php @@ -13,7 +13,7 @@ final class Composite implements ResourceDetectorInterface /** * @param iterable $resourceDetectors */ - public function __construct(private iterable $resourceDetectors) + public function __construct(private readonly iterable $resourceDetectors) { } diff --git a/src/SDK/Resource/Detectors/Constant.php b/src/SDK/Resource/Detectors/Constant.php index 0ebe98134..13fe613a5 100644 --- a/src/SDK/Resource/Detectors/Constant.php +++ b/src/SDK/Resource/Detectors/Constant.php @@ -9,7 +9,7 @@ final class Constant implements ResourceDetectorInterface { - public function __construct(private ResourceInfo $resourceInfo) + public function __construct(private readonly ResourceInfo $resourceInfo) { } diff --git a/src/SDK/Sdk.php b/src/SDK/Sdk.php index ac82c6052..8c6533f5e 100644 --- a/src/SDK/Sdk.php +++ b/src/SDK/Sdk.php @@ -16,10 +16,10 @@ class Sdk private const OTEL_PHP_DISABLED_INSTRUMENTATIONS_ALL = 'all'; public function __construct( - private TracerProviderInterface $tracerProvider, - private MeterProviderInterface $meterProvider, - private LoggerProviderInterface $loggerProvider, - private TextMapPropagatorInterface $propagator, + private readonly TracerProviderInterface $tracerProvider, + private readonly MeterProviderInterface $meterProvider, + private readonly LoggerProviderInterface $loggerProvider, + private readonly TextMapPropagatorInterface $propagator, ) { } diff --git a/src/SDK/SdkAutoloader.php b/src/SDK/SdkAutoloader.php index db288fe94..b1d5edca9 100644 --- a/src/SDK/SdkAutoloader.php +++ b/src/SDK/SdkAutoloader.php @@ -19,6 +19,9 @@ use OpenTelemetry\SDK\Trace\SpanProcessorFactory; use OpenTelemetry\SDK\Trace\TracerProviderBuilder; +/** + * @psalm-suppress RedundantCast + */ class SdkAutoloader { public static function autoload(): bool @@ -46,9 +49,9 @@ public static function autoload(): bool $loggerProvider = (new LoggerProviderFactory())->create($emitMetrics ? $meterProvider : null, $resource); - ShutdownHandler::register([$tracerProvider, 'shutdown']); - ShutdownHandler::register([$meterProvider, 'shutdown']); - ShutdownHandler::register([$loggerProvider, 'shutdown']); + ShutdownHandler::register($tracerProvider->shutdown(...)); + ShutdownHandler::register($meterProvider->shutdown(...)); + ShutdownHandler::register($loggerProvider->shutdown(...)); return $configurator ->withTracerProvider($tracerProvider) @@ -77,7 +80,7 @@ public static function isIgnoredUrl(): bool return false; } foreach ($ignoreUrls as $ignore) { - if (preg_match(sprintf('|%s|', $ignore), $url) === 1) { + if (preg_match(sprintf('|%s|', $ignore), (string) $url) === 1) { return true; } } @@ -116,7 +119,7 @@ public static function isExcludedUrl(): bool return false; } foreach ($excludedUrls as $excludedUrl) { - if (preg_match(sprintf('|%s|', $excludedUrl), $url) === 1) { + if (preg_match(sprintf('|%s|', $excludedUrl), (string) $url) === 1) { return true; } } diff --git a/src/SDK/SdkBuilder.php b/src/SDK/SdkBuilder.php index 0baeb95fb..22664b417 100644 --- a/src/SDK/SdkBuilder.php +++ b/src/SDK/SdkBuilder.php @@ -70,9 +70,9 @@ public function build(): Sdk $loggerProvider = $this->loggerProvider ?? new NoopLoggerProvider(); if ($this->autoShutdown) { // rector rule disabled in config, because ShutdownHandler::register() does not keep a strong reference to $this - ShutdownHandler::register([$tracerProvider, 'shutdown']); - ShutdownHandler::register([$meterProvider, 'shutdown']); - ShutdownHandler::register([$loggerProvider, 'shutdown']); + ShutdownHandler::register($tracerProvider->shutdown(...)); + ShutdownHandler::register($meterProvider->shutdown(...)); + ShutdownHandler::register($loggerProvider->shutdown(...)); } return new Sdk( diff --git a/src/SDK/Trace/Event.php b/src/SDK/Trace/Event.php index 468451fce..45c23218a 100644 --- a/src/SDK/Trace/Event.php +++ b/src/SDK/Trace/Event.php @@ -10,9 +10,9 @@ final class Event implements EventInterface { public function __construct( - private string $name, - private int $timestamp, - private AttributesInterface $attributes, + private readonly string $name, + private readonly int $timestamp, + private readonly AttributesInterface $attributes, ) { } diff --git a/src/SDK/Trace/ImmutableSpan.php b/src/SDK/Trace/ImmutableSpan.php index 77e29cb3e..ff86796af 100644 --- a/src/SDK/Trace/ImmutableSpan.php +++ b/src/SDK/Trace/ImmutableSpan.php @@ -21,15 +21,15 @@ final class ImmutableSpan implements SpanDataInterface * @param list $events */ public function __construct( - private Span $span, - private string $name, - private array $links, - private array $events, - private AttributesInterface $attributes, - private int $totalRecordedEvents, - private StatusDataInterface $status, - private int $endEpochNanos, - private bool $hasEnded, + private readonly Span $span, + private readonly string $name, + private readonly array $links, + private readonly array $events, + private readonly AttributesInterface $attributes, + private readonly int $totalRecordedEvents, + private readonly StatusDataInterface $status, + private readonly int $endEpochNanos, + private readonly bool $hasEnded, ) { } diff --git a/src/SDK/Trace/Link.php b/src/SDK/Trace/Link.php index 75f622bd8..871378297 100644 --- a/src/SDK/Trace/Link.php +++ b/src/SDK/Trace/Link.php @@ -10,8 +10,8 @@ final class Link implements LinkInterface { public function __construct( - private API\SpanContextInterface $context, - private AttributesInterface $attributes, + private readonly API\SpanContextInterface $context, + private readonly AttributesInterface $attributes, ) { } diff --git a/src/SDK/Trace/Sampler/ParentBased.php b/src/SDK/Trace/Sampler/ParentBased.php index 0b26102c1..fd34a7e58 100644 --- a/src/SDK/Trace/Sampler/ParentBased.php +++ b/src/SDK/Trace/Sampler/ParentBased.php @@ -29,13 +29,10 @@ */ class ParentBased implements SamplerInterface { - private SamplerInterface $remoteParentSampler; - - private SamplerInterface $remoteParentNotSampler; - - private SamplerInterface $localParentSampler; - - private SamplerInterface $localParentNotSampler; + private readonly SamplerInterface $remoteParentSampler; + private readonly SamplerInterface $remoteParentNotSampler; + private readonly SamplerInterface $localParentSampler; + private readonly SamplerInterface $localParentNotSampler; /** * ParentBased sampler delegates the sampling decision based on the parent context. @@ -47,7 +44,7 @@ class ParentBased implements SamplerInterface * @param SamplerInterface|null $localParentNotSampler Sampler called for the span with the local not sampled parent. When null, `AlwaysOffSampler` is used. */ public function __construct( - private SamplerInterface $root, + private readonly SamplerInterface $root, ?SamplerInterface $remoteParentSampler = null, ?SamplerInterface $remoteParentNotSampler = null, ?SamplerInterface $localParentSampler = null, diff --git a/src/SDK/Trace/Sampler/TraceIdRatioBasedSampler.php b/src/SDK/Trace/Sampler/TraceIdRatioBasedSampler.php index 0b26087d4..4f49e5865 100644 --- a/src/SDK/Trace/Sampler/TraceIdRatioBasedSampler.php +++ b/src/SDK/Trace/Sampler/TraceIdRatioBasedSampler.php @@ -21,7 +21,7 @@ */ class TraceIdRatioBasedSampler implements SamplerInterface { - private float $probability; + private readonly float $probability; /** * @param float $probability Probability float value between 0.0 and 1.0. diff --git a/src/SDK/Trace/SamplingResult.php b/src/SDK/Trace/SamplingResult.php index d78bca8ab..c09b03758 100644 --- a/src/SDK/Trace/SamplingResult.php +++ b/src/SDK/Trace/SamplingResult.php @@ -27,9 +27,9 @@ final class SamplingResult * @param ?API\TraceStateInterface $traceState A Tracestate that will be associated with the Span through the new SpanContext. */ public function __construct( - private int $decision, - private iterable $attributes = [], - private ?API\TraceStateInterface $traceState = null, + private readonly int $decision, + private readonly iterable $attributes = [], + private readonly ?API\TraceStateInterface $traceState = null, ) { } diff --git a/src/SDK/Trace/Span.php b/src/SDK/Trace/Span.php index 6e55f6e72..0dac95ba6 100644 --- a/src/SDK/Trace/Span.php +++ b/src/SDK/Trace/Span.php @@ -30,27 +30,17 @@ final class Span extends API\Span implements ReadWriteSpanInterface */ private function __construct( private string $name, - /** @readonly */ - private API\SpanContextInterface $context, - /** @readonly */ - private InstrumentationScopeInterface $instrumentationScope, - /** @readonly */ - private int $kind, - /** @readonly */ - private API\SpanContextInterface $parentSpanContext, - /** @readonly */ - private SpanLimits $spanLimits, - /** @readonly */ - private SpanProcessorInterface $spanProcessor, - /** @readonly */ - private ResourceInfo $resource, + private readonly API\SpanContextInterface $context, + private readonly InstrumentationScopeInterface $instrumentationScope, + private readonly int $kind, + private readonly API\SpanContextInterface $parentSpanContext, + private readonly SpanLimits $spanLimits, + private readonly SpanProcessorInterface $spanProcessor, + private readonly ResourceInfo $resource, private AttributesBuilderInterface $attributesBuilder, - /** @readonly */ - private array $links, - /** @readonly */ - private int $totalRecordedLinks, - /** @readonly */ - private int $startEpochNanos, + private readonly array $links, + private readonly int $totalRecordedLinks, + private readonly int $startEpochNanos, ) { $this->status = StatusData::unset(); } diff --git a/src/SDK/Trace/SpanBuilder.php b/src/SDK/Trace/SpanBuilder.php index 2d3320512..6df9b2b6b 100644 --- a/src/SDK/Trace/SpanBuilder.php +++ b/src/SDK/Trace/SpanBuilder.php @@ -29,12 +29,9 @@ final class SpanBuilder implements API\SpanBuilderInterface /** @param non-empty-string $spanName */ public function __construct( - /** @readonly */ - private string $spanName, - /** @readonly */ - private InstrumentationScopeInterface $instrumentationScope, - /** @readonly */ - private TracerSharedState $tracerSharedState, + private readonly string $spanName, + private readonly InstrumentationScopeInterface $instrumentationScope, + private readonly TracerSharedState $tracerSharedState, ) { $this->attributesBuilder = $this->tracerSharedState->getSpanLimits()->getAttributesFactory()->builder(); } diff --git a/src/SDK/Trace/SpanExporter/ConsoleSpanExporter.php b/src/SDK/Trace/SpanExporter/ConsoleSpanExporter.php index 96bbec6af..dbe3651c2 100644 --- a/src/SDK/Trace/SpanExporter/ConsoleSpanExporter.php +++ b/src/SDK/Trace/SpanExporter/ConsoleSpanExporter.php @@ -19,7 +19,7 @@ class ConsoleSpanExporter implements SpanExporterInterface use LogsMessagesTrait; public function __construct( - private TransportInterface $transport, + private readonly TransportInterface $transport, ?SpanConverterInterface $converter = null, ) { $this->setSpanConverter($converter ?? new FriendlySpanConverter()); diff --git a/src/SDK/Trace/SpanExporter/InMemoryExporter.php b/src/SDK/Trace/SpanExporter/InMemoryExporter.php index 04d2becb9..dd87b8ea1 100644 --- a/src/SDK/Trace/SpanExporter/InMemoryExporter.php +++ b/src/SDK/Trace/SpanExporter/InMemoryExporter.php @@ -12,11 +12,8 @@ class InMemoryExporter implements SpanExporterInterface { use SpanExporterTrait; - private ArrayObject $storage; - - public function __construct(?ArrayObject $storage = null) + public function __construct(private readonly ArrayObject $storage = new ArrayObject()) { - $this->storage = $storage ?? new ArrayObject(); } protected function doExport(iterable $spans): bool diff --git a/src/SDK/Trace/SpanLimits.php b/src/SDK/Trace/SpanLimits.php index f383ca0eb..4906b7f2f 100644 --- a/src/SDK/Trace/SpanLimits.php +++ b/src/SDK/Trace/SpanLimits.php @@ -46,11 +46,11 @@ public function getLinkCountLimit(): int * @internal Use {@see SpanLimitsBuilder} to create {@see SpanLimits} instance. */ public function __construct( - private AttributesFactoryInterface $attributesFactory, - private AttributesFactoryInterface $eventAttributesFactory, - private AttributesFactoryInterface $linkAttributesFactory, - private int $eventCountLimit, - private int $linkCountLimit, + private readonly AttributesFactoryInterface $attributesFactory, + private readonly AttributesFactoryInterface $eventAttributesFactory, + private readonly AttributesFactoryInterface $linkAttributesFactory, + private readonly int $eventCountLimit, + private readonly int $linkCountLimit, ) { } } diff --git a/src/SDK/Trace/SpanProcessor/BatchSpanProcessor.php b/src/SDK/Trace/SpanProcessor/BatchSpanProcessor.php index d59ab8d48..c697c4238 100644 --- a/src/SDK/Trace/SpanProcessor/BatchSpanProcessor.php +++ b/src/SDK/Trace/SpanProcessor/BatchSpanProcessor.php @@ -59,13 +59,13 @@ class BatchSpanProcessor implements SpanProcessorInterface private bool $closed = false; public function __construct( - private SpanExporterInterface $exporter, - private ClockInterface $clock, + private readonly SpanExporterInterface $exporter, + private readonly ClockInterface $clock, int $maxQueueSize = self::DEFAULT_MAX_QUEUE_SIZE, int $scheduledDelayMillis = self::DEFAULT_SCHEDULE_DELAY, int $exportTimeoutMillis = self::DEFAULT_EXPORT_TIMEOUT, int $maxExportBatchSize = self::DEFAULT_MAX_EXPORT_BATCH_SIZE, - private bool $autoFlush = true, + private readonly bool $autoFlush = true, ?MeterProviderInterface $meterProvider = null, ) { if ($maxQueueSize <= 0) { diff --git a/src/SDK/Trace/SpanProcessor/BatchSpanProcessorBuilder.php b/src/SDK/Trace/SpanProcessor/BatchSpanProcessorBuilder.php index 88a826f3a..c3229548f 100644 --- a/src/SDK/Trace/SpanProcessor/BatchSpanProcessorBuilder.php +++ b/src/SDK/Trace/SpanProcessor/BatchSpanProcessorBuilder.php @@ -12,7 +12,7 @@ class BatchSpanProcessorBuilder { private ?MeterProviderInterface $meterProvider = null; - public function __construct(private SpanExporterInterface $exporter) + public function __construct(private readonly SpanExporterInterface $exporter) { } diff --git a/src/SDK/Trace/SpanProcessor/SimpleSpanProcessor.php b/src/SDK/Trace/SpanProcessor/SimpleSpanProcessor.php index 246345fa9..7b65e58f4 100644 --- a/src/SDK/Trace/SpanProcessor/SimpleSpanProcessor.php +++ b/src/SDK/Trace/SpanProcessor/SimpleSpanProcessor.php @@ -28,7 +28,7 @@ class SimpleSpanProcessor implements SpanProcessorInterface private bool $closed = false; - public function __construct(private SpanExporterInterface $exporter) + public function __construct(private readonly SpanExporterInterface $exporter) { $this->exportContext = Context::getCurrent(); $this->queue = new SplQueue(); diff --git a/src/SDK/Trace/StatusData.php b/src/SDK/Trace/StatusData.php index c53cda0a4..f1bd72789 100644 --- a/src/SDK/Trace/StatusData.php +++ b/src/SDK/Trace/StatusData.php @@ -14,8 +14,8 @@ final class StatusData implements StatusDataInterface /** @psalm-param API\StatusCode::STATUS_* $code */ public function __construct( - private string $code, - private string $description, + private readonly string $code, + private readonly string $description, ) { } diff --git a/src/SDK/Trace/Tracer.php b/src/SDK/Trace/Tracer.php index baf7a049c..5f9c56920 100644 --- a/src/SDK/Trace/Tracer.php +++ b/src/SDK/Trace/Tracer.php @@ -14,10 +14,8 @@ class Tracer implements API\TracerInterface public const FALLBACK_SPAN_NAME = 'empty'; public function __construct( - /** @readonly */ - private TracerSharedState $tracerSharedState, - /** @readonly */ - private InstrumentationScopeInterface $instrumentationScope, + private readonly TracerSharedState $tracerSharedState, + private readonly InstrumentationScopeInterface $instrumentationScope, ) { } diff --git a/src/SDK/Trace/TracerProvider.php b/src/SDK/Trace/TracerProvider.php index 40cf81919..f0eda6843 100644 --- a/src/SDK/Trace/TracerProvider.php +++ b/src/SDK/Trace/TracerProvider.php @@ -18,23 +18,19 @@ final class TracerProvider implements TracerProviderInterface { - /** @readonly */ - private TracerSharedState $tracerSharedState; - private InstrumentationScopeFactoryInterface $instrumentationScopeFactory; + private readonly TracerSharedState $tracerSharedState; + private readonly InstrumentationScopeFactoryInterface $instrumentationScopeFactory; /** @param list|SpanProcessorInterface|null $spanProcessors */ public function __construct( - $spanProcessors = [], + SpanProcessorInterface|array|null $spanProcessors = [], SamplerInterface $sampler = null, ResourceInfo $resource = null, SpanLimits $spanLimits = null, IdGeneratorInterface $idGenerator = null, ?InstrumentationScopeFactoryInterface $instrumentationScopeFactory = null, ) { - if (null === $spanProcessors) { - $spanProcessors = []; - } - + $spanProcessors ??= []; $spanProcessors = is_array($spanProcessors) ? $spanProcessors : [$spanProcessors]; $resource ??= ResourceInfoFactory::defaultResource(); $sampler ??= new ParentBased(new AlwaysOnSampler()); diff --git a/src/SDK/Trace/TracerProviderFactory.php b/src/SDK/Trace/TracerProviderFactory.php index b12136e7e..38d013d3e 100644 --- a/src/SDK/Trace/TracerProviderFactory.php +++ b/src/SDK/Trace/TracerProviderFactory.php @@ -11,18 +11,11 @@ final class TracerProviderFactory { use LogsMessagesTrait; - private ExporterFactory $exporterFactory; - private SamplerFactory $samplerFactory; - private SpanProcessorFactory $spanProcessorFactory; - public function __construct( - ?ExporterFactory $exporterFactory = null, - ?SamplerFactory $samplerFactory = null, - ?SpanProcessorFactory $spanProcessorFactory = null, + private readonly ExporterFactory $exporterFactory = new ExporterFactory(), + private readonly SamplerFactory $samplerFactory = new SamplerFactory(), + private readonly SpanProcessorFactory $spanProcessorFactory = new SpanProcessorFactory(), ) { - $this->exporterFactory = $exporterFactory ?: new ExporterFactory(); - $this->samplerFactory = $samplerFactory ?: new SamplerFactory(); - $this->spanProcessorFactory = $spanProcessorFactory ?: new SpanProcessorFactory(); } public function create(): TracerProviderInterface diff --git a/src/SDK/Trace/TracerSharedState.php b/src/SDK/Trace/TracerSharedState.php index bcc5aa83e..3d6a38988 100644 --- a/src/SDK/Trace/TracerSharedState.php +++ b/src/SDK/Trace/TracerSharedState.php @@ -15,20 +15,15 @@ */ final class TracerSharedState { - /** @readonly */ - private SpanProcessorInterface $spanProcessor; + private readonly SpanProcessorInterface $spanProcessor; private ?bool $shutdownResult = null; public function __construct( - /** @readonly */ - private IdGeneratorInterface $idGenerator, - /** @readonly */ - private ResourceInfo $resource, - /** @readonly */ - private SpanLimits $spanLimits, - /** @readonly */ - private SamplerInterface $sampler, + private readonly IdGeneratorInterface $idGenerator, + private readonly ResourceInfo $resource, + private readonly SpanLimits $spanLimits, + private readonly SamplerInterface $sampler, array $spanProcessors, ) { $this->spanProcessor = match (count($spanProcessors)) { diff --git a/src/SDK/composer.json b/src/SDK/composer.json index cfff80c24..599014235 100644 --- a/src/SDK/composer.json +++ b/src/SDK/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.1", "ext-json": "*", "open-telemetry/api": "^1.0", "open-telemetry/context": "^1.0", @@ -29,7 +29,6 @@ "psr/http-message": "^1.0.1|^2.0", "psr/log": "^1.1|^2.0|^3.0", "symfony/polyfill-mbstring": "^1.23", - "symfony/polyfill-php81": "^1.26", "symfony/polyfill-php82": "^1.26" }, "autoload": { diff --git a/src/SemConv/composer.json b/src/SemConv/composer.json index 110b7277a..c890f40fe 100644 --- a/src/SemConv/composer.json +++ b/src/SemConv/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "^8.0" + "php": "^8.1" }, "autoload": { "psr-4": { diff --git a/tests/Integration/SDK/ParentBasedTest.php b/tests/Integration/SDK/ParentBasedTest.php index 8f83c9b41..1ea40138d 100644 --- a/tests/Integration/SDK/ParentBasedTest.php +++ b/tests/Integration/SDK/ParentBasedTest.php @@ -5,10 +5,7 @@ namespace OpenTelemetry\Tests\Integration\SDK; use OpenTelemetry\API\Trace as API; -use OpenTelemetry\API\Trace\NonRecordingSpan; -use OpenTelemetry\API\Trace\SpanContext; use OpenTelemetry\Context\Context; -use OpenTelemetry\Context\ContextInterface; use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\Sampler\ParentBased; use OpenTelemetry\SDK\Trace\SamplerInterface; @@ -35,92 +32,6 @@ public function test_parent_based_root_span(): void ); } - /** - * @dataProvider parentContextData - */ - public function test_parent_based( - ContextInterface $parentContext, - ?SamplerInterface $remoteParentSampled = null, - ?SamplerInterface $remoteParentNotSampled = null, - ?SamplerInterface $localParentSampled = null, - ?SamplerInterface $localParentNotSampled = null, - ?int $expectedDecision = null, - ): void { - $rootSampler = $this->createMockSamplerNeverInvoked(); - - $sampler = new ParentBased($rootSampler, $remoteParentSampled, $remoteParentNotSampled, $localParentSampled, $localParentNotSampled); - $decision = $sampler->shouldSample( - $parentContext, - '4bf92f3577b34da6a3ce929d0e0e4736', - 'test.opentelemetry.io', - API\SpanKind::KIND_INTERNAL, - Attributes::create([]), - [], - ); - $this->assertEquals($expectedDecision, $decision->getDecision()); - } - - public function parentContextData(): array - { - return [ - // remote, sampled, default sampler - [$this->createParentContext(true, true), null, null, null, null, SamplingResult::RECORD_AND_SAMPLE], - // remote, not sampled, default sampler - [$this->createParentContext(false, true), null, null, null, null, SamplingResult::DROP], - // local, sampled, default sampler - [$this->createParentContext(true, false), null, null, null, null, SamplingResult::RECORD_AND_SAMPLE], - // local, not sampled, default sampler - [$this->createParentContext(false, false), null, null, null, null, SamplingResult::DROP], - // remote, sampled - [$this->createParentContext(true, true), $this->createMockSamplerInvokedOnce(SamplingResult::RECORD_AND_SAMPLE), null, null, null, SamplingResult::RECORD_AND_SAMPLE], - // remote, not sampled - [$this->createParentContext(false, true), null, $this->createMockSamplerInvokedOnce(SamplingResult::DROP), null, null, SamplingResult::DROP], - // local, sampled - [$this->createParentContext(true, false), null, null, $this->createMockSamplerInvokedOnce(SamplingResult::RECORD_AND_SAMPLE), null, SamplingResult::RECORD_AND_SAMPLE], - // local, not sampled - [$this->createParentContext(false, false), null, null, null, $this->createMockSamplerInvokedOnce(SamplingResult::DROP), SamplingResult::DROP], - ]; - } - - public function test_parent_based_description(): void - { - $rootSampler = $this->createMock(SamplerInterface::class); - $rootSampler->expects($this->once())->method('getDescription')->willReturn('Foo'); - $sampler = new ParentBased($rootSampler); - $this->assertEquals('ParentBased+Foo', $sampler->getDescription()); - } - - private function createParentContext(bool $sampled, bool $isRemote, ?API\TraceStateInterface $traceState = null): ContextInterface - { - $traceFlag = $sampled ? API\TraceFlags::SAMPLED : API\TraceFlags::DEFAULT; - - if ($isRemote) { - $spanContext = SpanContext::createFromRemoteParent( - '4bf92f3577b34da6a3ce929d0e0e4736', - '00f067aa0ba902b7', - $traceFlag, - $traceState - ); - } else { - $spanContext = SpanContext::create( - '4bf92f3577b34da6a3ce929d0e0e4736', - '00f067aa0ba902b7', - $traceFlag, - $traceState - ); - } - - return Context::getRoot()->withContextValue(new NonRecordingSpan($spanContext)); - } - - private function createMockSamplerNeverInvoked(): SamplerInterface - { - $sampler = $this->createMock(SamplerInterface::class); - $sampler->expects($this->never())->method('shouldSample'); - - return $sampler; - } - private function createMockSamplerInvokedOnce(int $resultDecision): SamplerInterface { $sampler = $this->createMock(SamplerInterface::class);