diff --git a/composer.json b/composer.json index c9f868e..3ba7e5c 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "type": "library", "license": "MIT", "require": { - "php": "^7.1" + "php": "^7.1|^8" }, "authors": [ { diff --git a/src/Exporter.php b/src/Exporter.php index b0ce219..e9a2c6a 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -9,9 +9,9 @@ abstract class Exporter { - abstract public function convertSpan(Span $span) : array; + abstract public function convertSpan(Span $span): array; - public function flush(Tracer $tracer, Transport $transport) : int + public function flush(Tracer $tracer, Transport $transport): int { $data = []; @@ -25,4 +25,4 @@ public function flush(Tracer $tracer, Transport $transport) : int return count($data); } -} \ No newline at end of file +} diff --git a/src/Exporter/ZipkinExporter.php b/src/Exporter/ZipkinExporter.php index 31baefd..f759f54 100644 --- a/src/Exporter/ZipkinExporter.php +++ b/src/Exporter/ZipkinExporter.php @@ -12,18 +12,16 @@ class ZipkinExporter extends Exporter { private $endpoint; - public function convertSpan(Span $span) : array + public function convertSpan(Span $span): array { $row = [ 'id' => $span->getSpanContext()->getSpanId(), 'traceId' => $span->getSpanContext()->getTraceId(), - 'parentId' => $span->getParentSpanContext() - ? $span->getParentSpanContext()->getSpanId() - : null, + 'parentId' => $span->getParentSpanContext() ? $span->getParentSpanContext()->getSpanId() : null, 'localEndpoint' => $this->getEndpoint(), 'name' => $span->getName(), - 'timestamp' => (integer) round($span->getStart()*1000000), - 'duration' => (integer) round($span->getEnd()*1000000) - round($span->getStart()*1000000), + 'timestamp' => (int) round($span->getStart() * 1000000), + 'duration' => (int) round($span->getEnd() * 1000000) - round($span->getStart() * 1000000), ]; foreach ($span->getAttributes() as $k => $v) { @@ -41,7 +39,7 @@ public function convertSpan(Span $span) : array $row['annotations'] = []; } $row['annotations'][] = [ - 'timestamp' => round($event->getTimestamp()*1000000), + 'timestamp' => round($event->getTimestamp() * 1000000), 'value' => $event->getName(), ]; } @@ -54,7 +52,7 @@ public function getEndpoint() return $this->endpoint; } - public function setEndpoint(array $endpoint) : self + public function setEndpoint(array $endpoint): self { $this->endpoint = $endpoint; return $this; diff --git a/src/Tracing/Builder.php b/src/Tracing/Builder.php index a5641a0..b2d0fb2 100644 --- a/src/Tracing/Builder.php +++ b/src/Tracing/Builder.php @@ -10,10 +10,10 @@ class Builder public static function create() { - return new self; + return new self(); } - public function setSpanContext(SpanContext $spanContext) : self + public function setSpanContext(SpanContext $spanContext): self { $this->spanContext = $spanContext; return $this; @@ -23,4 +23,4 @@ public function getTracer() { return new Tracer($this->spanContext); } -} \ No newline at end of file +} diff --git a/src/Tracing/Event.php b/src/Tracing/Event.php index 9c79ec5..84e7e68 100644 --- a/src/Tracing/Event.php +++ b/src/Tracing/Event.php @@ -12,7 +12,7 @@ class Event public function __construct(string $name, array $attributes = [], $timestamp = null) { - if (is_null($timestamp)) { + if ($timestamp === null) { $timestamp = microtime(true); } $this->name = $name; @@ -28,18 +28,18 @@ public function getAttribute(string $key) return $this->attributes[$key]; } - public function setAttribute(string $key, $value) : self + public function setAttribute(string $key, $value): self { $this->attributes[$key] = $value; return $this; } - public function getAttributes() : array + public function getAttributes(): array { return $this->attributes; } - public function setAttributes(array $attributes) : self + public function setAttributes(array $attributes): self { $this->attributes = []; foreach ($attributes as $k => $v) { @@ -48,13 +48,13 @@ public function setAttributes(array $attributes) : self return $this; } - public function getName() : string + public function getName(): string { return $this->name; } - public function getTimestamp() : float + public function getTimestamp(): float { return $this->timestamp; } -} \ No newline at end of file +} diff --git a/src/Tracing/Span.php b/src/Tracing/Span.php index 42bb472..1d10f12 100644 --- a/src/Tracing/Span.php +++ b/src/Tracing/Span.php @@ -27,23 +27,23 @@ public function __construct(string $name, SpanContext $spanContext, SpanContext $this->start = microtime(true); } - public function getSpanContext() : SpanContext + public function getSpanContext(): SpanContext { return $this->spanContext; } - public function getParentSpanContext() : ?SpanContext + public function getParentSpanContext(): ?SpanContext { return $this->parentSpanContext; } - public function setParentSpanContext(SpanContext $parentSpanContext = null) : self + public function setParentSpanContext(SpanContext $parentSpanContext = null): self { $this->parentSpanContext = $parentSpanContext; return $this; } - public function end(Status $status = null) : self + public function end(Status $status = null): self { $this->end = microtime(true); if (!$this->status && !$status) { @@ -65,23 +65,23 @@ public function getEnd() return $this->end; } - public function setStatus(Status $status) : self + public function setStatus(Status $status): self { $this->status = $status; return $this; } - public function getStatus() : ?Status + public function getStatus(): ?Status { return $this->status; } - public function isRecordingEvents() : bool + public function isRecordingEvents(): bool { - return is_null($this->end); + return $this->end === null; } - public function getDuration() : ?float + public function getDuration(): ?float { if (!$this->end) { return null; @@ -89,19 +89,19 @@ public function getDuration() : ?float return $this->end - $this->start; } - public function getName() : string + public function getName(): string { return $this->name; } - public function setInterval(float $start, ?float $end) : self + public function setInterval(float $start, ?float $end): self { $this->start = $start; $this->end = $end; return $this; } - public function setName(string $name) : self + public function setName(string $name): self { $this->name = $name; return $this; @@ -115,7 +115,7 @@ public function getAttribute(string $key) return $this->attributes[$key]; } - public function setAttribute(string $key, $value) : self + public function setAttribute(string $key, $value): self { $this->throwExceptionIfReadonly(); @@ -123,12 +123,12 @@ public function setAttribute(string $key, $value) : self return $this; } - public function getAttributes() : array + public function getAttributes(): array { return $this->attributes; } - public function setAttributes(array $attributes) : self + public function setAttributes(array $attributes): self { $this->throwExceptionIfReadonly(); @@ -139,7 +139,7 @@ public function setAttributes(array $attributes) : self return $this; } - public function addEvent(string $name, array $attributes = [], float $timestamp = null) : Event + public function addEvent(string $name, array $attributes = [], float $timestamp = null): Event { $this->throwExceptionIfReadonly(); @@ -159,4 +159,4 @@ private function throwExceptionIfReadonly() throw new Exception("Span is readonly"); } } -} \ No newline at end of file +} diff --git a/src/Tracing/SpanContext.php b/src/Tracing/SpanContext.php index c357afe..4dec6f1 100644 --- a/src/Tracing/SpanContext.php +++ b/src/Tracing/SpanContext.php @@ -30,13 +30,13 @@ public function __construct(string $traceId, string $spanId) $this->spanId = $spanId; } - public function getTraceId() : string + public function getTraceId(): string { return $this->traceId; } - public function getSpanId() : string + public function getSpanId(): string { return $this->spanId; } -} \ No newline at end of file +} diff --git a/src/Tracing/Status.php b/src/Tracing/Status.php index 71bf42d..ca86b4d 100644 --- a/src/Tracing/Status.php +++ b/src/Tracing/Status.php @@ -6,25 +6,25 @@ class Status { - const OK = 0; - const CANCELLED = 1; - const UNKNOWN = 2; - const INVALID_ARGUMENT = 3; - const DEADLINE_EXCEEDED = 4; - const NOT_FOUND = 5; - const ALREADY_EXISTS = 6; - const PERMISSION_DENIED = 7; - const RESOURCE_EXHAUSTED = 8; - const FAILED_PRECONDITION = 9; - const ABORTED = 10; - const OUT_OF_RANGE = 11; - const UNIMPLEMENTED = 12; - const INTERNAL = 13; - const UNAVAILABLE = 14; - const DATA_LOSS = 15; - const UNAUTHENTICATED = 16; + public const OK = 0; + public const CANCELLED = 1; + public const UNKNOWN = 2; + public const INVALID_ARGUMENT = 3; + public const DEADLINE_EXCEEDED = 4; + public const NOT_FOUND = 5; + public const ALREADY_EXISTS = 6; + public const PERMISSION_DENIED = 7; + public const RESOURCE_EXHAUSTED = 8; + public const FAILED_PRECONDITION = 9; + public const ABORTED = 10; + public const OUT_OF_RANGE = 11; + public const UNIMPLEMENTED = 12; + public const INTERNAL = 13; + public const UNAVAILABLE = 14; + public const DATA_LOSS = 15; + public const UNAUTHENTICATED = 16; - const DESCRIPTION = [ + public const DESCRIPTION = [ 0 => 'Not an error; returned on success.', 1 => 'The operation was cancelled, typically by the caller.', 2 => 'Unknown error. For example, this error may be returned when a Status value received from another address space belongs to an error space that is not known in this address space. Also errors raised by APIs that do not return enough error information may be converted to this error.', @@ -53,23 +53,23 @@ public function __construct(int $code, string $description = null) if (!$description && array_key_exists($code, self::DESCRIPTION)) { $description = self::DESCRIPTION[$code]; } - if (!is_null($description)) { + if ($description !== null) { $this->description = $description; } } - public function getCanonicalCode() : int + public function getCanonicalCode(): int { return $this->code; } - public function getDescription() : ?string + public function getDescription(): ?string { return $this->description; } - public function isOk() : bool + public function isOk(): bool { return $this->code == self::OK; } -} \ No newline at end of file +} diff --git a/src/Tracing/Tracer.php b/src/Tracing/Tracer.php index 1016452..3c59598 100644 --- a/src/Tracing/Tracer.php +++ b/src/Tracing/Tracer.php @@ -16,7 +16,7 @@ public function __construct(SpanContext $context = null) $this->active = $this->generateSpanInstance('tracer', $context); } - public function getActiveSpan() : Span + public function getActiveSpan(): Span { while (count($this->tail) && $this->active->getEnd()) { $this->active = array_pop($this->tail); @@ -24,13 +24,13 @@ public function getActiveSpan() : Span return $this->active; } - public function setActive(Span $span) : Span + public function setActive(Span $span): Span { $this->tail[] = $this->active; return $this->active = $span; } - public function createSpan(string $name) : Span + public function createSpan(string $name): Span { $parent = $this->getActiveSpan()->getSpanContext(); $context = SpanContext::fork($parent->getTraceId()); @@ -38,12 +38,12 @@ public function createSpan(string $name) : Span return $this->setActive($span); } - public function getSpans() : array + public function getSpans(): array { return $this->spans; } - private function generateSpanInstance($name, SpanContext $context) : Span + private function generateSpanInstance($name, SpanContext $context): Span { $parent = null; if ($this->active) { @@ -53,4 +53,4 @@ private function generateSpanInstance($name, SpanContext $context) : Span $this->spans[] = $span; return $span; } -} \ No newline at end of file +} diff --git a/src/Transport.php b/src/Transport.php index 8972b2e..18cdbbd 100644 --- a/src/Transport.php +++ b/src/Transport.php @@ -6,5 +6,5 @@ interface Transport { - public function write(array $data) : bool; -} \ No newline at end of file + public function write(array $data): bool; +} diff --git a/src/Transport/TarantoolQueueTransport.php b/src/Transport/TarantoolQueueTransport.php index eb52bbf..122e846 100644 --- a/src/Transport/TarantoolQueueTransport.php +++ b/src/Transport/TarantoolQueueTransport.php @@ -12,12 +12,12 @@ class TarantoolQueueTransport implements Transport { private $queue; - public function write(array $data) : bool + public function write(array $data): bool { return $this->getQueue()->put($data) ? true : false; } - public function getQueue() : Queue + public function getQueue(): Queue { if (!$this->queue) { throw new Exception("Queue should be set"); @@ -25,9 +25,9 @@ public function getQueue() : Queue return $this->queue; } - public function setQueue(Queue $queue) : self + public function setQueue(Queue $queue): self { $this->queue = $queue; return $this; } -} \ No newline at end of file +}