Skip to content

Commit 69825d3

Browse files
authored
fix implicit null usage (#1362)
php8.4 deprecates implicit null (now checked by phan)
1 parent 80e97da commit 69825d3

14 files changed

+27
-29
lines changed

src/API/Baggage/BaggageBuilder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function remove(string $key): BaggageBuilderInterface
2020
}
2121

2222
/** @inheritDoc */
23-
public function set(string $key, $value, MetadataInterface $metadata = null): BaggageBuilderInterface
23+
public function set(string $key, $value, ?MetadataInterface $metadata = null): BaggageBuilderInterface
2424
{
2525
$metadata ??= Metadata::getEmpty();
2626

src/API/Baggage/BaggageBuilderInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface BaggageBuilderInterface
1111
/**
1212
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/baggage/api.md#set-value
1313
*/
14-
public function set(string $key, mixed $value, API\MetadataInterface $metadata = null): API\BaggageBuilderInterface;
14+
public function set(string $key, mixed $value, ?API\MetadataInterface $metadata = null): API\BaggageBuilderInterface;
1515

1616
/**
1717
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/baggage/api.md#remove-value

src/API/Logs/EventLoggerInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function emit(
1616
mixed $body = null,
1717
?int $timestamp = null,
1818
?ContextInterface $context = null,
19-
Severity $severityNumber = null,
19+
?Severity $severityNumber = null,
2020
iterable $attributes = [],
2121
): void;
2222
}

src/API/Logs/LogRecord.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function setBody(mixed $body = null): self
9393
/**
9494
* @param int|null $observedTimestamp Time, in nanoseconds since the unix epoch, when the event was observed by the collection system.
9595
*/
96-
public function setObservedTimestamp(int $observedTimestamp = null): self
96+
public function setObservedTimestamp(?int $observedTimestamp = null): self
9797
{
9898
$this->observedTimestamp = $observedTimestamp;
9999

src/API/Trace/NonRecordingSpan.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function addLink(SpanContextInterface $context, iterable $attributes = []
4747
}
4848

4949
/** @inheritDoc */
50-
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null): SpanInterface
50+
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null): SpanInterface
5151
{
5252
return $this;
5353
}
@@ -65,13 +65,13 @@ public function updateName(string $name): SpanInterface
6565
}
6666

6767
/** @inheritDoc */
68-
public function setStatus(string $code, string $description = null): SpanInterface
68+
public function setStatus(string $code, ?string $description = null): SpanInterface
6969
{
7070
return $this;
7171
}
7272

7373
/** @inheritDoc */
74-
public function end(int $endEpochNanos = null): void
74+
public function end(?int $endEpochNanos = null): void
7575
{
7676
}
7777
}

src/API/Trace/SpanInterface.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function addLink(SpanContextInterface $context, iterable $attributes = []
8383
/**
8484
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#add-events
8585
*/
86-
public function addEvent(string $name, iterable $attributes = [], int $timestamp = null): SpanInterface;
86+
public function addEvent(string $name, iterable $attributes = [], ?int $timestamp = null): SpanInterface;
8787

8888
/**
8989
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#record-exception
@@ -102,10 +102,10 @@ public function updateName(string $name): SpanInterface;
102102
*
103103
* @psalm-param StatusCode::STATUS_* $code
104104
*/
105-
public function setStatus(string $code, string $description = null): SpanInterface;
105+
public function setStatus(string $code, ?string $description = null): SpanInterface;
106106

107107
/**
108108
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#end
109109
*/
110-
public function end(int $endEpochNanos = null): void;
110+
public function end(?int $endEpochNanos = null): void;
111111
}

src/Context/Propagation/MultiTextMapPropagator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public function fields(): array
3232
return $this->fields;
3333
}
3434

35-
public function inject(&$carrier, PropagationSetterInterface $setter = null, ContextInterface $context = null): void
35+
public function inject(&$carrier, ?PropagationSetterInterface $setter = null, ?ContextInterface $context = null): void
3636
{
3737
foreach ($this->propagators as $propagator) {
3838
$propagator->inject($carrier, $setter, $context);
3939
}
4040
}
4141

42-
public function extract($carrier, PropagationGetterInterface $getter = null, ContextInterface $context = null): ContextInterface
42+
public function extract($carrier, ?PropagationGetterInterface $getter = null, ?ContextInterface $context = null): ContextInterface
4343
{
4444
$context ??= Context::getCurrent();
4545

src/Contrib/Zipkin/Exporter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Exporter implements SpanExporterInterface
2525

2626
public function __construct(
2727
private readonly TransportInterface $transport,
28-
SpanConverterInterface $spanConverter = null,
28+
?SpanConverterInterface $spanConverter = null,
2929
) {
3030
$this->setSpanConverter($spanConverter ?? new SpanConverter());
3131
}

src/SDK/Common/Dev/Compatibility/Util.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function getErrorLevel(): int
3333
/**
3434
* @psalm-suppress ArgumentTypeCoercion
3535
*/
36-
public static function triggerClassDeprecationNotice(string $className, string $alternativeClassName = null): void
36+
public static function triggerClassDeprecationNotice(string $className, ?string $alternativeClassName = null): void
3737
{
3838
if (self::getErrorLevel() === self::E_NONE) {
3939
return;
@@ -56,8 +56,8 @@ public static function triggerClassDeprecationNotice(string $className, string $
5656
*/
5757
public static function triggerMethodDeprecationNotice(
5858
string $methodName,
59-
string $alternativeMethodName = null,
60-
string $alternativeClassName = null,
59+
?string $alternativeMethodName = null,
60+
?string $alternativeClassName = null,
6161
): void {
6262
if (self::getErrorLevel() === self::E_NONE) {
6363
return;

src/SDK/Logs/EventLogger.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function emit(
3131
mixed $body = null,
3232
?int $timestamp = null,
3333
?ContextInterface $context = null,
34-
Severity $severityNumber = null,
34+
?Severity $severityNumber = null,
3535
iterable $attributes = [],
3636
): void {
3737
$logRecord = new LogRecord();

src/SDK/Logs/LoggerProvider.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public function getLogger(string $name, ?string $version = null, ?string $schema
5050
return $logger;
5151
}
5252

53-
public function shutdown(CancellationInterface $cancellation = null): bool
53+
public function shutdown(?CancellationInterface $cancellation = null): bool
5454
{
5555
return $this->loggerSharedState->shutdown($cancellation);
5656
}
5757

58-
public function forceFlush(CancellationInterface $cancellation = null): bool
58+
public function forceFlush(?CancellationInterface $cancellation = null): bool
5959
{
6060
return $this->loggerSharedState->forceFlush($cancellation);
6161
}

src/SDK/Metrics/MeterProvider.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
final class MeterProvider implements MeterProviderInterface
2525
{
26-
private readonly MetricFactoryInterface $metricFactory;
2726
private readonly MeterInstruments $instruments;
2827
private readonly MetricRegistryInterface $registry;
2928
private readonly MetricWriterInterface $writer;
@@ -45,10 +44,9 @@ public function __construct(
4544
private readonly ViewRegistryInterface $viewRegistry,
4645
private readonly ?ExemplarFilterInterface $exemplarFilter,
4746
private readonly StalenessHandlerFactoryInterface $stalenessHandlerFactory,
48-
MetricFactoryInterface $metricFactory = null,
47+
private readonly MetricFactoryInterface $metricFactory = new StreamFactory(),
4948
private ?Configurator $configurator = null,
5049
) {
51-
$this->metricFactory = $metricFactory ?? new StreamFactory();
5250
$this->instruments = new MeterInstruments();
5351

5452
$registry = new MetricRegistry($contextStorage, $attributesFactory, $clock);

src/SDK/Trace/Span.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static function startSpan(
100100
*
101101
* @codeCoverageIgnore
102102
*/
103-
public static function formatStackTrace(Throwable $e, array &$seen = null): string
103+
public static function formatStackTrace(Throwable $e, ?array &$seen = null): string
104104
{
105105
BcUtil::triggerMethodDeprecationNotice(
106106
__METHOD__,
@@ -224,7 +224,7 @@ public function updateName(string $name): self
224224
}
225225

226226
/** @inheritDoc */
227-
public function setStatus(string $code, string $description = null): self
227+
public function setStatus(string $code, ?string $description = null): self
228228
{
229229
if ($this->hasEnded) {
230230
return $this;
@@ -245,7 +245,7 @@ public function setStatus(string $code, string $description = null): self
245245
}
246246

247247
/** @inheritDoc */
248-
public function end(int $endEpochNanos = null): void
248+
public function end(?int $endEpochNanos = null): void
249249
{
250250
if ($this->hasEnded) {
251251
return;

src/SDK/Trace/TracerProvider.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ final class TracerProvider implements TracerProviderInterface
2727
/** @param list<SpanProcessorInterface>|SpanProcessorInterface|null $spanProcessors */
2828
public function __construct(
2929
SpanProcessorInterface|array|null $spanProcessors = [],
30-
SamplerInterface $sampler = null,
31-
ResourceInfo $resource = null,
32-
SpanLimits $spanLimits = null,
33-
IdGeneratorInterface $idGenerator = null,
30+
?SamplerInterface $sampler = null,
31+
?ResourceInfo $resource = null,
32+
?SpanLimits $spanLimits = null,
33+
?IdGeneratorInterface $idGenerator = null,
3434
?InstrumentationScopeFactoryInterface $instrumentationScopeFactory = null,
3535
private ?Configurator $configurator = null,
3636
) {

0 commit comments

Comments
 (0)