Skip to content

Commit

Permalink
readonly and typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Mar 13, 2024
1 parent 5e17db3 commit d6c5f56
Show file tree
Hide file tree
Showing 40 changed files with 149 additions and 282 deletions.
2 changes: 1 addition & 1 deletion src/API/Baggage/Baggage.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function getEmpty(): BaggageInterface
}

/** @param array<string, Entry> $entries */
public function __construct(private array $entries = [])
public function __construct(private readonly array $entries = [])
{
}

Expand Down
1 change: 0 additions & 1 deletion src/API/Baggage/Propagation/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ final class Parser
private const EQUALS = '=';

public function __construct(
/** @readonly */
private readonly string $baggageHeader,
) {
}
Expand Down
15 changes: 3 additions & 12 deletions src/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions src/Context/FiberBoundContextStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
*/
final class FiberBoundContextStorage implements ContextStorageInterface, ExecutionContextAwareInterface
{
/**
* @param ContextStorageInterface&ExecutionContextAwareInterface $storage
*/
public function __construct(private readonly ContextStorageInterface $storage)
public function __construct(private readonly ContextStorageInterface&ExecutionContextAwareInterface $storage)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/Contrib/Zipkin/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Common/Attribute/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class Attributes implements AttributesInterface, IteratorAggregate
* @internal
*/
public function __construct(
private array $attributes,
private readonly array $attributes,
private readonly int $droppedAttributesCount,
) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Common/Attribute/AttributesFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/SDK/Logs/Processor/BatchLogRecordProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Logs/Processor/MultiLogRecordProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class MultiLogRecordProcessor implements LogRecordProcessorInterface
{
// @var LogRecordProcessorInterface[]
// @var list<LogRecordProcessorInterface>
private array $processors = [];

public function __construct(array $processors)
Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Logs/SimplePsrFileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
15 changes: 5 additions & 10 deletions src/SDK/Metrics/Data/Exemplar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ final class Exemplar
{
public function __construct(
private readonly int|string $index,
/** @readonly */
public float|int $value,
/** @readonly */
public int $timestamp,
/** @readonly */
public AttributesInterface $attributes,
/** @readonly */
public ?string $traceId,
/** @readonly */
public ?string $spanId,
public readonly float|int $value,
public readonly int $timestamp,
public readonly AttributesInterface $attributes,
public readonly ?string $traceId,
public readonly ?string $spanId,
) {
}

Expand Down
3 changes: 1 addition & 2 deletions src/SDK/Metrics/Data/Gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ final class Gauge implements DataInterface
* @param iterable<NumberDataPoint> $dataPoints
*/
public function __construct(
/** @readonly */
public iterable $dataPoints,
public readonly iterable $dataPoints,
) {
}
}
6 changes: 2 additions & 4 deletions src/SDK/Metrics/Data/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ final class Histogram implements DataInterface
* @param iterable<HistogramDataPoint> $dataPoints
*/
public function __construct(
/** @readonly */
public iterable $dataPoints,
/** @readonly */
public string|Temporality $temporality,
public readonly iterable $dataPoints,
public readonly string|Temporality $temporality,
) {
}
}
30 changes: 10 additions & 20 deletions src/SDK/Metrics/Data/HistogramDataPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,16 @@ final class HistogramDataPoint
* @param list<float|int> $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 = [],
) {
}
}
18 changes: 6 additions & 12 deletions src/SDK/Metrics/Data/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
}
15 changes: 5 additions & 10 deletions src/SDK/Metrics/Data/NumberDataPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [],
) {
}
}
9 changes: 3 additions & 6 deletions src/SDK/Metrics/Data/Sum.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ final class Sum implements DataInterface
* @param iterable<NumberDataPoint> $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,
) {
}
}
15 changes: 5 additions & 10 deletions src/SDK/Metrics/Instrument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [],
) {
}
}
24 changes: 12 additions & 12 deletions src/SDK/Metrics/Meter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ final class Meter implements MeterInterface
* @param ArrayAccess<object, ObservableCallbackDestructor> $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,
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Metrics/MetricReader/ExportingReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function __construct(
$this->staleHandlers = new WeakMap();
}

public function create(): StalenessHandlerInterface
public function create(): ReferenceCounterInterface&StalenessHandlerInterface
{
$this->triggerStaleHandlers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 1 addition & 4 deletions src/SDK/Metrics/StalenessHandlerFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

interface StalenessHandlerFactoryInterface
{
/**
* @return StalenessHandlerInterface&ReferenceCounterInterface
*/
public function create(): StalenessHandlerInterface;
public function create(): StalenessHandlerInterface&ReferenceCounterInterface;
}
Loading

0 comments on commit d6c5f56

Please sign in to comment.