Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
php 8 support, cs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Dec 14, 2020
1 parent 9a3b313 commit 3bb20ce
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 77 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^7.1"
"php": "^7.1|^8"
},
"authors": [
{
Expand Down
6 changes: 3 additions & 3 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -25,4 +25,4 @@ public function flush(Tracer $tracer, Transport $transport) : int

return count($data);
}
}
}
14 changes: 6 additions & 8 deletions src/Exporter/ZipkinExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(),
];
}
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Tracing/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,4 +23,4 @@ public function getTracer()
{
return new Tracer($this->spanContext);
}
}
}
14 changes: 7 additions & 7 deletions src/Tracing/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
}
}
34 changes: 17 additions & 17 deletions src/Tracing/Span.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -65,43 +65,43 @@ 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;
}
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;
Expand All @@ -115,20 +115,20 @@ 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();

$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->throwExceptionIfReadonly();

Expand All @@ -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();

Expand All @@ -159,4 +159,4 @@ private function throwExceptionIfReadonly()
throw new Exception("Span is readonly");
}
}
}
}
6 changes: 3 additions & 3 deletions src/Tracing/SpanContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
46 changes: 23 additions & 23 deletions src/Tracing/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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;
}
}
}
12 changes: 6 additions & 6 deletions src/Tracing/Tracer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@ 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);
}
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());
$span = $this->generateSpanInstance($name, $context);
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) {
Expand All @@ -53,4 +53,4 @@ private function generateSpanInstance($name, SpanContext $context) : Span
$this->spans[] = $span;
return $span;
}
}
}
Loading

0 comments on commit 3bb20ce

Please sign in to comment.