diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 77c8f42..49c2ea4 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -2,4 +2,8 @@ require_once 'vendor/autoload.php'; -return CodingStandards\Factory::createPhpCsFixerConfig(__DIR__); +return CodingStandards\Factory::createPhpCsFixerConfig(__DIR__, [ + 'rules' => [ + 'nullable_type_declaration' => ['syntax' => 'union'] + ] +]); diff --git a/composer.json b/composer.json index 95bafbb..616b383 100644 --- a/composer.json +++ b/composer.json @@ -2,11 +2,19 @@ "name": "worldia/instrumentation-bundle", "type": "symfony-bundle", "license": "MIT", - "keywords": ["instrumentation", "tracing", "metrics", "open-telemetry", "prometheus"], - "authors": [{ - "name": "Worldia developers", - "email": "developers@worldia.com" - }], + "keywords": [ + "instrumentation", + "tracing", + "metrics", + "open-telemetry", + "prometheus" + ], + "authors": [ + { + "name": "Worldia developers", + "email": "developers@worldia.com" + } + ], "require": { "monolog/monolog": "^2.0", "nyholm/dsn": "^2.0", @@ -20,11 +28,10 @@ "require-dev": { "doctrine/dbal": "^3.0", "friends-of-phpspec/phpspec-expect": "^4.0", - "open-telemetry/sdk-contrib": "^1.0@dev", "open-telemetry/transport-grpc": "^1.0", "open-telemetry/gen-otlp-protobuf": "^1.0", "php-http/httplug": "^2.3", - "phpspec/phpspec": "^7.2", + "phpspec/phpspec": "^7.5", "phpstan/phpstan": "^1.4", "symfony/framework-bundle": "*", "symfony/http-client": "*", diff --git a/spec/Baggage/Propagation/Http/BaggageHeaderProviderSpec.php b/spec/Baggage/Propagation/Http/BaggageHeaderProviderSpec.php index ba48a27..fd3eb3b 100644 --- a/spec/Baggage/Propagation/Http/BaggageHeaderProviderSpec.php +++ b/spec/Baggage/Propagation/Http/BaggageHeaderProviderSpec.php @@ -14,7 +14,7 @@ class BaggageHeaderProviderSpec extends ObjectBehavior { - private ?ScopeInterface $scope = null; + private ScopeInterface|null $scope = null; public function let() { diff --git a/spec/Baggage/Propagation/Messenger/BaggageStampSpec.php b/spec/Baggage/Propagation/Messenger/BaggageStampSpec.php index eec21aa..b62b928 100644 --- a/spec/Baggage/Propagation/Messenger/BaggageStampSpec.php +++ b/spec/Baggage/Propagation/Messenger/BaggageStampSpec.php @@ -15,7 +15,7 @@ class BaggageStampSpec extends ObjectBehavior { - private ?ScopeInterface $scope = null; + private ScopeInterface|null $scope = null; public function let() { diff --git a/spec/Tracing/Instrumentation/EventSubscriber/CommandEventSubscriberSpec.php b/spec/Tracing/Instrumentation/EventSubscriber/CommandEventSubscriberSpec.php index 4dcaa2d..505cf13 100644 --- a/spec/Tracing/Instrumentation/EventSubscriber/CommandEventSubscriberSpec.php +++ b/spec/Tracing/Instrumentation/EventSubscriber/CommandEventSubscriberSpec.php @@ -146,7 +146,7 @@ private function createConsoleCommandEvent(Command|null $command = null): Consol return new ConsoleCommandEvent($command, new ArrayInput([]), new NullOutput()); } - private function createConsoleErrorEvent(Command|null $command = null): ConsoleErrorEvent + private function createConsoleErrorEvent(): ConsoleErrorEvent { return new ConsoleErrorEvent(new ArrayInput([]), new NullOutput(), new \Exception()); } diff --git a/src/Baggage/Propagation/ContextInitializer.php b/src/Baggage/Propagation/ContextInitializer.php index fc9b978..c05c3f4 100644 --- a/src/Baggage/Propagation/ContextInitializer.php +++ b/src/Baggage/Propagation/ContextInitializer.php @@ -17,7 +17,7 @@ final class ContextInitializer { - public static function fromRequest(Request $request): ?ScopeInterface + public static function fromRequest(Request $request): ScopeInterface|null { if (!$baggage = $request->headers->get(BaggagePropagator::BAGGAGE)) { return null; @@ -26,7 +26,7 @@ public static function fromRequest(Request $request): ?ScopeInterface return static::activateContext($baggage); } - public static function fromMessage(Envelope $envelope): ?ScopeInterface + public static function fromMessage(Envelope $envelope): ScopeInterface|null { /** @var BaggageStamp|null $stamp */ $stamp = $envelope->last(BaggageStamp::class); @@ -38,7 +38,7 @@ public static function fromMessage(Envelope $envelope): ?ScopeInterface return static::activateContext($stamp->getBaggage()); } - public static function fromW3CHeader(string $header): ?ScopeInterface + public static function fromW3CHeader(string $header): ScopeInterface|null { return static::activateContext($header); } diff --git a/src/Baggage/Propagation/EventSubscriber/MessengerEventSubscriber.php b/src/Baggage/Propagation/EventSubscriber/MessengerEventSubscriber.php index 995e710..755d19a 100644 --- a/src/Baggage/Propagation/EventSubscriber/MessengerEventSubscriber.php +++ b/src/Baggage/Propagation/EventSubscriber/MessengerEventSubscriber.php @@ -18,7 +18,7 @@ class MessengerEventSubscriber implements EventSubscriberInterface { - private ?ScopeInterface $scope = null; + private ScopeInterface|null $scope = null; public static function getSubscribedEvents(): array { diff --git a/src/Baggage/Propagation/EventSubscriber/RequestEventSubscriber.php b/src/Baggage/Propagation/EventSubscriber/RequestEventSubscriber.php index 75bf55a..1309804 100644 --- a/src/Baggage/Propagation/EventSubscriber/RequestEventSubscriber.php +++ b/src/Baggage/Propagation/EventSubscriber/RequestEventSubscriber.php @@ -17,7 +17,7 @@ class RequestEventSubscriber implements EventSubscriberInterface { - private ?ScopeInterface $scope = null; + private ScopeInterface|null $scope = null; public static function getSubscribedEvents(): array { diff --git a/src/Bridge/GoogleCloud/Logging/Formatter/StdOutFormatter.php b/src/Bridge/GoogleCloud/Logging/Formatter/StdOutFormatter.php index 8fddc35..7e8ec7a 100644 --- a/src/Bridge/GoogleCloud/Logging/Formatter/StdOutFormatter.php +++ b/src/Bridge/GoogleCloud/Logging/Formatter/StdOutFormatter.php @@ -101,7 +101,7 @@ protected function normalizeException(\Throwable $e, int $depth = 0): array * * @param array $trace The stack trace returned from Exception::getTrace() */ - private static function getFunctionNameForReport(?array $trace = null): string + private static function getFunctionNameForReport(array|null $trace = null): string { if (null === $trace) { return ''; diff --git a/src/Health/Controller/Endpoint.php b/src/Health/Controller/Endpoint.php index cf57368..e0d97c6 100644 --- a/src/Health/Controller/Endpoint.php +++ b/src/Health/Controller/Endpoint.php @@ -31,7 +31,7 @@ public static function getProvidedMetrics(): array /** * @param iterable $checks */ - public function __construct(private ResourceInfo $resourceInfo, private iterable $checks, private ?RegistryInterface $registry = null, private ?Profiler $profiler = null) + public function __construct(private ResourceInfo $resourceInfo, private iterable $checks, private RegistryInterface|null $registry = null, private Profiler|null $profiler = null) { } diff --git a/src/Health/HealtcheckInterface.php b/src/Health/HealtcheckInterface.php index 9b50a92..4cf365f 100644 --- a/src/Health/HealtcheckInterface.php +++ b/src/Health/HealtcheckInterface.php @@ -17,14 +17,14 @@ interface HealtcheckInterface public function getName(): string; - public function getDescription(): ?string; + public function getDescription(): string|null; /** * Contextual information about the status. * Should be returned when the check is failing to give additional * information about the reason for the current status. */ - public function getStatusMessage(): ?string; + public function getStatusMessage(): string|null; /** * @return string One of the HealtcheckInterface constants diff --git a/src/Http/TracedResponse.php b/src/Http/TracedResponse.php index e8b42d9..988768f 100644 --- a/src/Http/TracedResponse.php +++ b/src/Http/TracedResponse.php @@ -21,7 +21,7 @@ class TracedResponse implements ResponseInterface, StreamableInterface { - private ?string $content = null; + private string|null $content = null; /** @var resource|null */ private $stream; @@ -110,7 +110,7 @@ public function cancel(): void } } - public function getInfo(?string $type = null): mixed + public function getInfo(string|null $type = null): mixed { return $this->response->getInfo($type); } @@ -139,7 +139,7 @@ public function toStream(bool $throw = true) * * @internal */ - public static function stream(HttpClientInterface $client, iterable $responses, ?float $timeout): \Generator + public static function stream(HttpClientInterface $client, iterable $responses, float|null $timeout): \Generator { $wrappedResponses = []; $traceableMap = new \SplObjectStorage(); diff --git a/src/Http/TracingHttpClient.php b/src/Http/TracingHttpClient.php index 552b401..6da6f49 100644 --- a/src/Http/TracingHttpClient.php +++ b/src/Http/TracingHttpClient.php @@ -39,8 +39,8 @@ final class TracingHttpClient implements HttpClientInterface */ public function __construct( HttpClientInterface|array|null $client = null, - ?ClientRequestOperationNameResolverInterface $operationNameResolver = null, - ?ClientRequestAttributeProviderInterface $attributeProvider = null, + ClientRequestOperationNameResolverInterface|null $operationNameResolver = null, + ClientRequestAttributeProviderInterface|null $attributeProvider = null, int $maxHostConnections = 6, int $maxPendingPushes = 50 ) { @@ -61,7 +61,7 @@ public function __construct( * * @return array */ - protected function getExtraSpanAttributes(?array $attributes): array + protected function getExtraSpanAttributes(array|null $attributes): array { $attributes = $attributes ?: $_SERVER['OTEL_PHP_HTTP_SPAN_ATTRIBUTES'] ?? []; @@ -140,7 +140,7 @@ public function request(string $method, string $url, array $options = []): Respo return new TracedResponse($this->client->request($method, $url, $options), $span); } - public function stream(ResponseInterface|iterable $responses, ?float $timeout = null): ResponseStreamInterface + public function stream(ResponseInterface|iterable $responses, float|null $timeout = null): ResponseStreamInterface { if ($responses instanceof ResponseInterface) { $responses = [$responses]; diff --git a/src/Logging/Formatter/JsonFormatter.php b/src/Logging/Formatter/JsonFormatter.php index bd02ccb..9c9d26d 100644 --- a/src/Logging/Formatter/JsonFormatter.php +++ b/src/Logging/Formatter/JsonFormatter.php @@ -14,7 +14,7 @@ class JsonFormatter extends BaseJsonFormatter { - private ?int $lengthLimit = null; + private int|null $lengthLimit = null; public function format(array $record): string { diff --git a/src/Logging/Logging.php b/src/Logging/Logging.php index 6506b5a..6953073 100644 --- a/src/Logging/Logging.php +++ b/src/Logging/Logging.php @@ -15,9 +15,9 @@ class Logging { - private static ?LoggerInterface $logger = null; + private static LoggerInterface|null $logger = null; - public function __construct(?LoggerInterface $logger) + public function __construct(LoggerInterface|null $logger) { if (self::$logger) { return; diff --git a/src/Metrics/Controller/Endpoint.php b/src/Metrics/Controller/Endpoint.php index c0eaccd..808a8ff 100644 --- a/src/Metrics/Controller/Endpoint.php +++ b/src/Metrics/Controller/Endpoint.php @@ -16,7 +16,7 @@ final class Endpoint { - public function __construct(private CollectorRegistry $registry, private ?Profiler $profiler = null) + public function __construct(private CollectorRegistry $registry, private Profiler|null $profiler = null) { } diff --git a/src/Metrics/EventSubscriber/RequestEventSubscriber.php b/src/Metrics/EventSubscriber/RequestEventSubscriber.php index 92d9f3d..c906771 100644 --- a/src/Metrics/EventSubscriber/RequestEventSubscriber.php +++ b/src/Metrics/EventSubscriber/RequestEventSubscriber.php @@ -49,7 +49,7 @@ public static function getProvidedMetrics(): array /** * @param array $blacklist */ - public function __construct(private RegistryInterface $registry, private array $blacklist, private ?MainSpanContextInterface $mainSpanContext = null) + public function __construct(private RegistryInterface $registry, private array $blacklist, private MainSpanContextInterface|null $mainSpanContext = null) { } diff --git a/src/Metrics/Meter.php b/src/Metrics/Meter.php index 3bdaeec..86426c1 100644 --- a/src/Metrics/Meter.php +++ b/src/Metrics/Meter.php @@ -37,7 +37,7 @@ public function __construct( * * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#counter-creation */ - public function createCounter(string $name, ?string $unit = null, ?string $description = null, array $advisory = []): CounterInterface + public function createCounter(string $name, string|null $unit = null, string|null $description = null, array $advisory = []): CounterInterface { return new CounterAdapter($name, $description ?: '', $this->collectorRegistry); } @@ -56,7 +56,7 @@ public function createCounter(string $name, ?string $unit = null, ?string $descr * * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#asynchronous-counter-creation */ - public function createObservableCounter(string $name, ?string $unit = null, ?string $description = null, $advisory = [], callable ...$callbacks): ObservableCounterInterface + public function createObservableCounter(string $name, string|null $unit = null, string|null $description = null, $advisory = [], callable ...$callbacks): ObservableCounterInterface { throw new \LogicException(sprintf('Method %s is not implemented', __METHOD__)); } @@ -74,7 +74,7 @@ public function createObservableCounter(string $name, ?string $unit = null, ?str * * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#histogram-creation */ - public function createHistogram(string $name, ?string $unit = null, ?string $description = null, array $advisory = []): HistogramInterface + public function createHistogram(string $name, string|null $unit = null, string|null $description = null, array $advisory = []): HistogramInterface { return new HistogramAdapter($name, $description ?: '', $this->collectorRegistry); } @@ -93,7 +93,7 @@ public function createHistogram(string $name, ?string $unit = null, ?string $des * * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#asynchronous-gauge-creation */ - public function createObservableGauge(string $name, ?string $unit = null, ?string $description = null, $advisory = [], callable ...$callbacks): ObservableGaugeInterface + public function createObservableGauge(string $name, string|null $unit = null, string|null $description = null, $advisory = [], callable ...$callbacks): ObservableGaugeInterface { throw new \LogicException(sprintf('Method %s is not implemented', __METHOD__)); } @@ -110,7 +110,7 @@ public function createObservableGauge(string $name, ?string $unit = null, ?strin * * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#updowncounter-creation */ - public function createUpDownCounter(string $name, ?string $unit = null, ?string $description = null, array $advisory = []): UpDownCounterInterface + public function createUpDownCounter(string $name, string|null $unit = null, string|null $description = null, array $advisory = []): UpDownCounterInterface { return new UpDownCounterAdapter($name, $description ?: '', $this->collectorRegistry); } @@ -129,7 +129,7 @@ public function createUpDownCounter(string $name, ?string $unit = null, ?string * * @see https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#asynchronous-updowncounter-creation */ - public function createObservableUpDownCounter(string $name, ?string $unit = null, ?string $description = null, $advisory = [], callable ...$callbacks): ObservableUpDownCounterInterface + public function createObservableUpDownCounter(string $name, string|null $unit = null, string|null $description = null, $advisory = [], callable ...$callbacks): ObservableUpDownCounterInterface { throw new \LogicException(sprintf('Method %s is not implemented', __METHOD__)); } diff --git a/src/Metrics/MetricDefinition.php b/src/Metrics/MetricDefinition.php index 4c3b0ea..889fb86 100644 --- a/src/Metrics/MetricDefinition.php +++ b/src/Metrics/MetricDefinition.php @@ -24,7 +24,7 @@ public function __construct( private string $type, private string $help, private array $labels = [], - private ?array $buckets = null + private array|null $buckets = null ) { } @@ -59,7 +59,7 @@ public function getHelp(): string /** * @return array */ - public function getBuckets(): ?array + public function getBuckets(): array|null { return $this->buckets; } diff --git a/src/Metrics/Metrics.php b/src/Metrics/Metrics.php index e5e04d8..29758ab 100644 --- a/src/Metrics/Metrics.php +++ b/src/Metrics/Metrics.php @@ -11,7 +11,7 @@ final class Metrics { - private static ?RegistryInterface $registry = null; + private static RegistryInterface|null $registry = null; public static function getRegistry(): RegistryInterface { diff --git a/src/Metrics/Storage/HostnamePrefixedRedisFactory.php b/src/Metrics/Storage/HostnamePrefixedRedisFactory.php index a3985f5..1a63699 100644 --- a/src/Metrics/Storage/HostnamePrefixedRedisFactory.php +++ b/src/Metrics/Storage/HostnamePrefixedRedisFactory.php @@ -12,7 +12,7 @@ final class HostnamePrefixedRedisFactory { - public function __construct(private ?RedisPrefixProvider $redisPrefixProvider) + public function __construct(private RedisPrefixProvider|null $redisPrefixProvider) { } diff --git a/src/Metrics/Storage/RedisPrefixProvider.php b/src/Metrics/Storage/RedisPrefixProvider.php index 93a2597..54110ff 100644 --- a/src/Metrics/Storage/RedisPrefixProvider.php +++ b/src/Metrics/Storage/RedisPrefixProvider.php @@ -9,7 +9,7 @@ class RedisPrefixProvider { - protected static ?RedisPrefixProvider $instance = null; + protected static RedisPrefixProvider|null $instance = null; protected string $prefix; protected function __construct() diff --git a/src/Semantics/Attribute/ServerRequestAttributeProvider.php b/src/Semantics/Attribute/ServerRequestAttributeProvider.php index 3f78e25..6e7392d 100644 --- a/src/Semantics/Attribute/ServerRequestAttributeProvider.php +++ b/src/Semantics/Attribute/ServerRequestAttributeProvider.php @@ -17,7 +17,7 @@ class ServerRequestAttributeProvider implements ServerRequestAttributeProviderIn /** * @param array $capturedHeaders */ - public function __construct(private ?string $serverName = null, private array $capturedHeaders = []) + public function __construct(private string|null $serverName = null, private array $capturedHeaders = []) { } diff --git a/src/Semantics/OperationName/CommandOperationNameResolver.php b/src/Semantics/OperationName/CommandOperationNameResolver.php index a1679c6..ce7d7ed 100644 --- a/src/Semantics/OperationName/CommandOperationNameResolver.php +++ b/src/Semantics/OperationName/CommandOperationNameResolver.php @@ -13,7 +13,7 @@ class CommandOperationNameResolver implements CommandOperationNameResolverInterface { - public function getOperationName(?Command $command): string + public function getOperationName(Command|null $command): string { $name = 'unknown-command'; diff --git a/src/Semantics/OperationName/CommandOperationNameResolverInterface.php b/src/Semantics/OperationName/CommandOperationNameResolverInterface.php index 14d248f..6b83796 100644 --- a/src/Semantics/OperationName/CommandOperationNameResolverInterface.php +++ b/src/Semantics/OperationName/CommandOperationNameResolverInterface.php @@ -16,5 +16,5 @@ interface CommandOperationNameResolverInterface /** * @return string&non-empty-string */ - public function getOperationName(?Command $command): string; + public function getOperationName(Command|null $command): string; } diff --git a/src/Semantics/OperationName/RoutePath/RouteCacheWarmer.php b/src/Semantics/OperationName/RoutePath/RouteCacheWarmer.php index 9373140..134f45e 100644 --- a/src/Semantics/OperationName/RoutePath/RouteCacheWarmer.php +++ b/src/Semantics/OperationName/RoutePath/RouteCacheWarmer.php @@ -23,7 +23,7 @@ public function isOptional(): bool return true; } - public function warmUp(string $cacheDir, ?string $buildDir = null): array + public function warmUp(string $cacheDir, string|null $buildDir = null): array { $routes = []; foreach ($this->router->getRouteCollection() as $name => $route) { diff --git a/src/Semantics/OperationName/RoutePath/RoutePathResolver.php b/src/Semantics/OperationName/RoutePath/RoutePathResolver.php index b3a228a..fc9c1a6 100644 --- a/src/Semantics/OperationName/RoutePath/RoutePathResolver.php +++ b/src/Semantics/OperationName/RoutePath/RoutePathResolver.php @@ -13,7 +13,7 @@ public function __construct(private RouteCacheWarmer $routeCacheWarmer, private { } - public function resolve(string $routeName): ?string + public function resolve(string $routeName): string|null { $routePathCacheFilename = $this->routeCacheWarmer->getCacheFile($this->cacheDir); diff --git a/src/Semantics/OperationName/RoutePath/RoutePathResolverInterface.php b/src/Semantics/OperationName/RoutePath/RoutePathResolverInterface.php index 5917d12..0b5f999 100644 --- a/src/Semantics/OperationName/RoutePath/RoutePathResolverInterface.php +++ b/src/Semantics/OperationName/RoutePath/RoutePathResolverInterface.php @@ -9,5 +9,5 @@ interface RoutePathResolverInterface { - public function resolve(string $routeName): ?string; + public function resolve(string $routeName): string|null; } diff --git a/src/Semantics/ResourceInfoProvider.php b/src/Semantics/ResourceInfoProvider.php index d33231a..882edc9 100644 --- a/src/Semantics/ResourceInfoProvider.php +++ b/src/Semantics/ResourceInfoProvider.php @@ -15,7 +15,7 @@ class ResourceInfoProvider implements ResourceInfoProviderInterface { - private ?ResourceInfo $info = null; + private ResourceInfo|null $info = null; /** * @param array $attributes diff --git a/src/Tracing/Instrumentation/EventSubscriber/AddUserEventSubscriber.php b/src/Tracing/Instrumentation/EventSubscriber/AddUserEventSubscriber.php index 5f927e5..46a5420 100644 --- a/src/Tracing/Instrumentation/EventSubscriber/AddUserEventSubscriber.php +++ b/src/Tracing/Instrumentation/EventSubscriber/AddUserEventSubscriber.php @@ -30,7 +30,7 @@ public static function getSubscribedEvents(): array ]; } - public function __construct(private MainSpanContextInterface $mainSpanContext, private ?TokenStorageInterface $tokenStorage = null) + public function __construct(private MainSpanContextInterface $mainSpanContext, private TokenStorageInterface|null $tokenStorage = null) { } @@ -68,7 +68,7 @@ private function getRoles(UserInterface|\Stringable|string $user): array return []; } - private function getUsername(UserInterface|\Stringable|string $user): ?string + private function getUsername(UserInterface|\Stringable|string $user): string|null { if ($user instanceof UserInterface) { if (method_exists($user, 'getUserIdentifier')) { diff --git a/src/Tracing/Instrumentation/EventSubscriber/CommandEventSubscriber.php b/src/Tracing/Instrumentation/EventSubscriber/CommandEventSubscriber.php index 027c09b..a432984 100644 --- a/src/Tracing/Instrumentation/EventSubscriber/CommandEventSubscriber.php +++ b/src/Tracing/Instrumentation/EventSubscriber/CommandEventSubscriber.php @@ -26,8 +26,8 @@ class CommandEventSubscriber implements EventSubscriberInterface { use TracerAwareTrait; - private ?SpanInterface $span = null; - private ?ScopeInterface $scope = null; + private SpanInterface|null $span = null; + private ScopeInterface|null $scope = null; public static function getSubscribedEvents(): array { diff --git a/src/Tracing/Instrumentation/EventSubscriber/RequestEventSubscriber.php b/src/Tracing/Instrumentation/EventSubscriber/RequestEventSubscriber.php index 6ea9641..5215b8d 100644 --- a/src/Tracing/Instrumentation/EventSubscriber/RequestEventSubscriber.php +++ b/src/Tracing/Instrumentation/EventSubscriber/RequestEventSubscriber.php @@ -29,8 +29,8 @@ class RequestEventSubscriber implements EventSubscriberInterface { use TracerAwareTrait; - private ?SpanInterface $serverSpan = null; - private ?ScopeInterface $serverScope = null; + private SpanInterface|null $serverSpan = null; + private ScopeInterface|null $serverScope = null; /** * @var \SplObjectStorage diff --git a/src/Tracing/Instrumentation/MainSpanContext.php b/src/Tracing/Instrumentation/MainSpanContext.php index eed691b..d6a6a9c 100644 --- a/src/Tracing/Instrumentation/MainSpanContext.php +++ b/src/Tracing/Instrumentation/MainSpanContext.php @@ -14,8 +14,8 @@ final class MainSpanContext implements MainSpanContextInterface { - private ?SpanInterface $mainSpan = null; - private ?string $operationName = null; + private SpanInterface|null $mainSpan = null; + private string|null $operationName = null; public function setCurrent(): void { @@ -36,12 +36,12 @@ public function setMainSpan(SpanInterface $span): void $this->mainSpan = $span; } - public function getOperationName(): ?string + public function getOperationName(): string|null { return $this->operationName; } - public function setOperationName(?string $name): void + public function setOperationName(string|null $name): void { $this->operationName = $name; } diff --git a/src/Tracing/Instrumentation/MainSpanContextInterface.php b/src/Tracing/Instrumentation/MainSpanContextInterface.php index e77532a..9ff3a27 100644 --- a/src/Tracing/Instrumentation/MainSpanContextInterface.php +++ b/src/Tracing/Instrumentation/MainSpanContextInterface.php @@ -19,7 +19,7 @@ public function getMainSpan(): SpanInterface; public function setMainSpan(SpanInterface $span): void; - public function getOperationName(): ?string; + public function getOperationName(): string|null; - public function setOperationName(?string $name): void; + public function setOperationName(string|null $name): void; } diff --git a/src/Tracing/Instrumentation/TracerAwareTrait.php b/src/Tracing/Instrumentation/TracerAwareTrait.php index 061b6fc..646b898 100644 --- a/src/Tracing/Instrumentation/TracerAwareTrait.php +++ b/src/Tracing/Instrumentation/TracerAwareTrait.php @@ -38,7 +38,7 @@ protected function startSpan(string $name, array $attributes = []): SpanInterfac * @param array $attributes * @param SpanKind::KIND_* $kind */ - protected function traceFunction(string $name, array $attributes, callable $callback, ?Context $parentContext = null, ?int $kind = null): mixed + protected function traceFunction(string $name, array $attributes, callable $callback, Context|null $parentContext = null, int|null $kind = null): mixed { $span = $this->getTracer() ->spanBuilder($name) // @phpstan-ignore-line diff --git a/src/Tracing/Propagation/ContextInitializer.php b/src/Tracing/Propagation/ContextInitializer.php index c338a9f..ce46ee7 100644 --- a/src/Tracing/Propagation/ContextInitializer.php +++ b/src/Tracing/Propagation/ContextInitializer.php @@ -17,7 +17,7 @@ final class ContextInitializer { - public static function fromRequest(Request $request): ?ScopeInterface + public static function fromRequest(Request $request): ScopeInterface|null { if (!$traceparent = $request->headers->get(TraceContextPropagator::TRACEPARENT)) { return null; @@ -28,7 +28,7 @@ public static function fromRequest(Request $request): ?ScopeInterface return static::activateContext($traceparent, $tracestate); } - public static function fromMessage(Envelope $envelope): ?ScopeInterface + public static function fromMessage(Envelope $envelope): ScopeInterface|null { /** @var TraceContextStamp|null $stamp */ $stamp = $envelope->last(TraceContextStamp::class); @@ -45,7 +45,7 @@ public static function fromW3CHeader(string $header): ScopeInterface return static::activateContext($header); } - public static function activateContext(string $parent, ?string $state = null): ScopeInterface + public static function activateContext(string $parent, string|null $state = null): ScopeInterface { $context = TraceContextPropagator::getInstance()->extract(array_filter([ TraceContextPropagator::TRACEPARENT => $parent, diff --git a/src/Tracing/Propagation/Doctrine/TraceContextInfoProvider.php b/src/Tracing/Propagation/Doctrine/TraceContextInfoProvider.php index b1e0051..ceac5c2 100644 --- a/src/Tracing/Propagation/Doctrine/TraceContextInfoProvider.php +++ b/src/Tracing/Propagation/Doctrine/TraceContextInfoProvider.php @@ -22,9 +22,9 @@ class TraceContextInfoProvider implements TraceContextInfoProviderInterface /** * @var array */ - private ?array $info = null; + private array|null $info = null; - public function __construct(private ResourceInfo $resourceInfo, private ?MainSpanContextInterface $mainSpanContext = null, private ?RequestStack $requestStack = null) + public function __construct(private ResourceInfo $resourceInfo, private MainSpanContextInterface|null $mainSpanContext = null, private RequestStack|null $requestStack = null) { } diff --git a/src/Tracing/Propagation/EventSubscriber/MessengerEventSubscriber.php b/src/Tracing/Propagation/EventSubscriber/MessengerEventSubscriber.php index 1e30ff1..50fdc0b 100644 --- a/src/Tracing/Propagation/EventSubscriber/MessengerEventSubscriber.php +++ b/src/Tracing/Propagation/EventSubscriber/MessengerEventSubscriber.php @@ -21,9 +21,9 @@ class MessengerEventSubscriber implements EventSubscriberInterface { private LoggerInterface $logger; - private ?ScopeInterface $scope = null; + private ScopeInterface|null $scope = null; - public function __construct(?LoggerInterface $logger = null) + public function __construct(LoggerInterface|null $logger = null) { $this->logger = $logger ?? new NullLogger(); } diff --git a/src/Tracing/Propagation/EventSubscriber/RequestEventSubscriber.php b/src/Tracing/Propagation/EventSubscriber/RequestEventSubscriber.php index 0a7c875..7741470 100644 --- a/src/Tracing/Propagation/EventSubscriber/RequestEventSubscriber.php +++ b/src/Tracing/Propagation/EventSubscriber/RequestEventSubscriber.php @@ -26,7 +26,7 @@ public static function getSubscribedEvents(): array ]; } - public function __construct(private ForcableIdGenerator $forcableIdGenerator, private ?IncomingTraceHeaderResolverInterface $incomingTraceResolver = null) + public function __construct(private ForcableIdGenerator $forcableIdGenerator, private IncomingTraceHeaderResolverInterface|null $incomingTraceResolver = null) { } diff --git a/src/Tracing/Propagation/ForcableIdGenerator.php b/src/Tracing/Propagation/ForcableIdGenerator.php index 97c7d3a..0c9a24e 100644 --- a/src/Tracing/Propagation/ForcableIdGenerator.php +++ b/src/Tracing/Propagation/ForcableIdGenerator.php @@ -14,8 +14,8 @@ final class ForcableIdGenerator implements IdGeneratorInterface, ResetInterface { - private ?string $traceId = null; - private ?string $spanId = null; + private string|null $traceId = null; + private string|null $spanId = null; public function __construct(private IdGeneratorInterface $decorated) { diff --git a/src/Tracing/Propagation/IncomingTraceHeaderResolverInterface.php b/src/Tracing/Propagation/IncomingTraceHeaderResolverInterface.php index 7c8c2d7..626b0c2 100644 --- a/src/Tracing/Propagation/IncomingTraceHeaderResolverInterface.php +++ b/src/Tracing/Propagation/IncomingTraceHeaderResolverInterface.php @@ -13,9 +13,9 @@ interface IncomingTraceHeaderResolverInterface { - public function getTraceId(Request $request): ?string; + public function getTraceId(Request $request): string|null; - public function getSpanId(Request $request): ?string; + public function getSpanId(Request $request): string|null; - public function isSampled(Request $request): ?bool; + public function isSampled(Request $request): bool|null; } diff --git a/src/Tracing/Propagation/Messenger/TraceContextStamp.php b/src/Tracing/Propagation/Messenger/TraceContextStamp.php index dbe08c7..3e96e83 100644 --- a/src/Tracing/Propagation/Messenger/TraceContextStamp.php +++ b/src/Tracing/Propagation/Messenger/TraceContextStamp.php @@ -16,7 +16,7 @@ final class TraceContextStamp implements StampInterface { private string $traceParent; - private ?string $traceState; + private string|null $traceState; public function __construct() { @@ -36,7 +36,7 @@ public function getTraceParent(): string return $this->traceParent; } - public function getTraceState(): ?string + public function getTraceState(): string|null { return $this->traceState; } diff --git a/src/Tracing/Propagation/RegexIncomingTraceHeaderResolver.php b/src/Tracing/Propagation/RegexIncomingTraceHeaderResolver.php index 18d7e16..b298675 100644 --- a/src/Tracing/Propagation/RegexIncomingTraceHeaderResolver.php +++ b/src/Tracing/Propagation/RegexIncomingTraceHeaderResolver.php @@ -13,25 +13,25 @@ class RegexIncomingTraceHeaderResolver implements IncomingTraceHeaderResolverInterface { - public function __construct(private ?string $headerName = null, private ?string $regex = null) + public function __construct(private string|null $headerName = null, private string|null $regex = null) { } - public function getTraceId(Request $request): ?string + public function getTraceId(Request $request): string|null { $matches = $this->resolve($request); return $matches['trace'] ?? null; } - public function getSpanId(Request $request): ?string + public function getSpanId(Request $request): string|null { $matches = $this->resolve($request); return $matches['spanId'] ?? null; } - public function isSampled(Request $request): ?bool + public function isSampled(Request $request): bool|null { $matches = $this->resolve($request); diff --git a/src/Tracing/Sampling/TogglableSampler.php b/src/Tracing/Sampling/TogglableSampler.php index 4a1cfed..912cff3 100644 --- a/src/Tracing/Sampling/TogglableSampler.php +++ b/src/Tracing/Sampling/TogglableSampler.php @@ -20,7 +20,7 @@ final class TogglableSampler implements SamplerInterface, ResetInterface /** * @var int&SamplingResult::* */ - private ?int $nextDecision = null; + private int|null $nextDecision = null; public function __construct(private SamplerInterface $decorated) { diff --git a/src/Tracing/Serializer/Normalizer/ErrorNormalizer.php b/src/Tracing/Serializer/Normalizer/ErrorNormalizer.php index 0b5b03e..83a86ce 100644 --- a/src/Tracing/Serializer/Normalizer/ErrorNormalizer.php +++ b/src/Tracing/Serializer/Normalizer/ErrorNormalizer.php @@ -18,7 +18,7 @@ class ErrorNormalizer implements NormalizerInterface, SerializerAwareInterface { - public function __construct(private NormalizerInterface $decorated, private bool $addUrl = false, private ?TraceUrlGeneratorInterface $traceUrlGenerator = null) + public function __construct(private NormalizerInterface $decorated, private bool $addUrl = false, private TraceUrlGeneratorInterface|null $traceUrlGenerator = null) { } @@ -32,7 +32,7 @@ public function setSerializer(SerializerInterface $serializer): void /** * @return array */ - public function getSupportedTypes(?string $format): array + public function getSupportedTypes(string|null $format): array { return [ FlattenException::class => __CLASS__ === self::class, @@ -44,7 +44,7 @@ public function getSupportedTypes(?string $format): array * * @return array|\ArrayObject */ - public function normalize($exception, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null + public function normalize($exception, string|null $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { $data = $this->decorated->normalize($exception, $format, $context); @@ -66,7 +66,7 @@ public function normalize($exception, ?string $format = null, array $context = [ /** * @param array $context */ - public function supportsNormalization($data, ?string $format = null, array $context = []): bool + public function supportsNormalization($data, string|null $format = null, array $context = []): bool { return $this->decorated->supportsNormalization($data, $format, $context); } diff --git a/src/Tracing/Tracer.php b/src/Tracing/Tracer.php index 96741b5..eeb7357 100644 --- a/src/Tracing/Tracer.php +++ b/src/Tracing/Tracer.php @@ -21,7 +21,7 @@ public function __construct(private BaseTracerInterface $decorated) { } - public function trace(string $operation, ?array $attributes = null, ?int $kind = null, ?Context $parentContext = null): SpanInterface + public function trace(string $operation, array|null $attributes = null, int|null $kind = null, Context|null $parentContext = null): SpanInterface { return $this->decorated->spanBuilder($operation) ->setAttributes($attributes ?: []) diff --git a/src/Tracing/TracerInterface.php b/src/Tracing/TracerInterface.php index a9a4d38..e84340d 100644 --- a/src/Tracing/TracerInterface.php +++ b/src/Tracing/TracerInterface.php @@ -21,5 +21,5 @@ interface TracerInterface extends BaseTracerInterface * @param array $attributes * @param SpanKind::KIND_* $kind */ - public function trace(string $operation, ?array $attributes = null, ?int $kind = null, ?Context $parentContext = null): SpanInterface; + public function trace(string $operation, array|null $attributes = null, int|null $kind = null, Context|null $parentContext = null): SpanInterface; } diff --git a/src/Tracing/Tracing.php b/src/Tracing/Tracing.php index 25b3e3f..6cd3781 100644 --- a/src/Tracing/Tracing.php +++ b/src/Tracing/Tracing.php @@ -18,14 +18,14 @@ final class Tracing { public const NAME = 'io.opentelemetry.contrib.php'; - private static ?TracerProviderInterface $tracerProvider = null; + private static TracerProviderInterface|null $tracerProvider = null; /** * @param non-empty-string $operation * @param array $attributes * @param SpanKind::KIND_* $kind */ - public static function trace(string $operation, ?array $attributes = null, ?int $kind = null, ?Context $parentContext = null): SpanInterface + public static function trace(string $operation, array|null $attributes = null, int|null $kind = null, Context|null $parentContext = null): SpanInterface { return static::getTracer()->spanBuilder($operation) ->setAttributes($attributes ?: []) diff --git a/src/Tracing/Twig/Extension/TracingExtension.php b/src/Tracing/Twig/Extension/TracingExtension.php index 8a2b88a..c06e442 100644 --- a/src/Tracing/Twig/Extension/TracingExtension.php +++ b/src/Tracing/Twig/Extension/TracingExtension.php @@ -16,7 +16,7 @@ class TracingExtension extends AbstractExtension { - public function __construct(private ?TraceUrlGeneratorInterface $traceUrlGenerator = null) + public function __construct(private TraceUrlGeneratorInterface|null $traceUrlGenerator = null) { } @@ -33,7 +33,7 @@ public function getTraceId(): string return Span::getCurrent()->getContext()->getTraceId(); } - public function getTraceUrl(?string $traceId = null): ?string + public function getTraceUrl(string|null $traceId = null): string|null { if ($traceId && $this->traceUrlGenerator) { return $this->traceUrlGenerator->getTraceUrl($traceId);