Skip to content

Commit

Permalink
Apply rector Code Quality rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tidal committed Jul 2, 2022
1 parent 54e936c commit 015a55f
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/API/Baggage/Baggage.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getEntry(string $key): ?Entry
/** @inheritDoc */
public function getValue(string $key)
{
if ($entry = $this->getEntry($key)) {
if (($entry = $this->getEntry($key)) !== null) {
return $entry->getValue();
}

Expand Down
4 changes: 2 additions & 2 deletions src/API/Baggage/Propagation/BaggagePropagator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public function inject(&$carrier, PropagationSetterInterface $setter = null, Con
$value = urlencode($entry->getValue());
$headerString.= "{$key}={$value}";

if ($metadata = $entry->getMetadata()->getValue()) {
if (($metadata = $entry->getMetadata()->getValue()) !== '' && ($metadata = $entry->getMetadata()->getValue()) !== '0') {
$headerString .= ";{$metadata}";
}

$headerString .= ',';
}

if ($headerString) {
if ($headerString !== '' && $headerString !== '0') {
$headerString = rtrim($headerString, ',');
$setter->set($carrier, self::BAGGAGE, $headerString);
}
Expand Down
2 changes: 1 addition & 1 deletion src/API/Trace/Propagation/TraceContextPropagator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function inject(&$carrier, PropagationSetterInterface $setter = null, Con

// Build and inject the tracestate header
// Spec says to avoid sending empty tracestate headers
if ($tracestate = (string) $spanContext->getTraceState()) {
if (($tracestate = (string) $spanContext->getTraceState()) !== '') {
$setter->set($carrier, self::TRACESTATE, $tracestate);
}
}
Expand Down
11 changes: 4 additions & 7 deletions src/API/Trace/TraceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,11 @@ private function parse(string $rawTracestate): array
$vendor = explode(self::LIST_MEMBER_KEY_VALUE_SPLITTER, trim($listMember));

// There should only be one list-member per vendor separated by '='
if (count($vendor) === 2) {
// TODO: Log if we can't validate the key and value
if (count($vendor) === 2 && ($this->validateKey($vendor[0]) && $this->validateValue($vendor[1]))) {
$parsedTracestate[$vendor[0]] = $vendor[1];

// TODO: Log if we can't validate the key and value
if ($this->validateKey($vendor[0]) && $this->validateValue($vendor[1])) {
$parsedTracestate[$vendor[0]] = $vendor[1];

continue;
}
continue;
}
$invalid = true;

Expand Down
2 changes: 1 addition & 1 deletion src/Context/FiberBoundContextStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function scope(): ?ContextStorageScopeInterface
{
$this->checkFiberMismatch();

if (!$scope = $this->storage->scope()) {
if (($scope = $this->storage->scope()) === null) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Context/Propagation/ArrayAccessGetterSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private function resolveKey($carrier, string $key): string

foreach ($carrier as $k => $_) {
$k = (string) $k;
if (!strcasecmp($k, $key)) {
if (strcasecmp($k, $key) === 0) {
return $k;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Contrib/Context/Swoole/SwooleContextStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function scope(): ?ContextStorageScopeInterface
{
$this->handler->switchToActiveCoroutine();

if (!$scope = $this->storage->scope()) {
if (($scope = $this->storage->scope()) === null) {
return null;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Contrib/Jaeger/SpanConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ private static function convertOtelSpanDataToJaegerTags(SpanDataInterface $span)
$tags[$k] = $v;
}

$tags = self::buildTags($tags);

return $tags;
return self::buildTags($tags);
}

private static function buildTags(array $tagPairs): array
Expand Down
4 changes: 2 additions & 2 deletions src/Contrib/Jaeger/TagFactory/TagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static function createJaegerTagInstance(string $key, $value)
]);
}

if (is_integer($value)) {
if (is_int($value)) {
return new Tag([
'key' => $key,
'vType' => TagType::LONG,
Expand Down Expand Up @@ -67,7 +67,7 @@ private static function serializeArrayToString(array $arrayToSerialize): string
private static function recursivelySerializeArray($value): string
{
if (is_array($value)) {
return join(',', array_map(fn ($val) => self::recursivelySerializeArray($val), $value));
return implode(',', array_map(fn ($val) => self::recursivelySerializeArray($val), $value));
}

// Casting false to string makes an empty string
Expand Down
6 changes: 3 additions & 3 deletions src/Contrib/Otlp/SpanConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public function convert(iterable $spans): array
$instrumentationScope->getAttributes()->getDroppedAttributesCount(),
]);

if (!$pResourceSpans = $resourceSpans[$resourceId] ?? null) {
if (($pResourceSpans = $resourceSpans[$resourceId] ?? null) === null) {
/** @psalm-suppress InvalidArgument */
$pExportTraceServiceRequest->getResourceSpans()[]
= $resourceSpans[$resourceId]
= $pResourceSpans
= $this->convertResourceSpans($resource);
}

if (!$pScopeSpans = $scopeSpans[$resourceId][$instrumentationScopeId] ?? null) {
if (($pScopeSpans = $scopeSpans[$resourceId][$instrumentationScopeId] ?? null) === null) {
/** @psalm-suppress InvalidArgument */
$pResourceSpans->getScopeSpans()[]
= $scopeSpans[$resourceId][$instrumentationScopeId]
Expand Down Expand Up @@ -138,7 +138,7 @@ private function convertAnyValue($value): AnyValue
$result->setBoolValue($value);

break;
case is_double($value):
case is_float($value):
$result->setDoubleValue($value);

break;
Expand Down
2 changes: 1 addition & 1 deletion src/Contrib/OtlpHttp/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private function validateEndpoint(string $endpoint): string

if ($dsn->getScheme() === null) {
$dsn = $dsn->withScheme('https');
} elseif (!($dsn->getScheme() === 'https' || $dsn->getScheme() === 'http')) {
} elseif ($dsn->getScheme() !== 'https' && $dsn->getScheme() !== 'http') {
throw new InvalidArgumentException('Expected scheme of http or https, given: ' . $dsn->getScheme());
}

Expand Down
8 changes: 3 additions & 5 deletions src/Contrib/Zipkin/SpanConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private function sanitiseTagValue($value)
// Zipkin tags must be strings, but opentelemetry
// accepts strings, booleans, numbers, and lists of each.
if (is_array($value)) {
return implode(',', array_map([$this, 'sanitiseTagValue'], $value));
return implode(',', array_map(fn ($value) => $this->sanitiseTagValue($value), $value));
}

// Floats will lose precision if their string representation
Expand Down Expand Up @@ -169,12 +169,10 @@ private static function toAnnotation(EventInterface $event): array

$value = ($attributesAsJson !== null) ? sprintf('"%s": %s', $eventName, $attributesAsJson) : sprintf('"%s"', $eventName);

$annotation = [
return [
'timestamp' => TimeUtil::nanosToMicros($event->getEpochNanos()),
'value' => $value,
];

return $annotation;
}

private static function convertEventAttributesToJson(EventInterface $event): ?string
Expand All @@ -184,7 +182,7 @@ private static function convertEventAttributesToJson(EventInterface $event): ?st
}

$attributesAsJson = json_encode($event->getAttributes()->toArray());
if (($attributesAsJson === false) || (strlen($attributesAsJson) === 0)) {
if (($attributesAsJson === false) || ($attributesAsJson === '')) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Contrib/ZipkinToNewrelic/SpanConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private function sanitiseTagValue($value)
// Zipkin tags must be strings, but opentelemetry
// accepts strings, booleans, numbers, and lists of each.
if (is_array($value)) {
return implode(',', array_map([$this, 'sanitiseTagValue'], $value));
return implode(',', array_map(fn ($value) => $this->sanitiseTagValue($value), $value));
}

// Floats will lose precision if their string representation
Expand Down
3 changes: 2 additions & 1 deletion src/SDK/Common/Exception/StackTraceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ private static function frames(Throwable $e): array
{
$frames = [];
$trace = $e->getTrace();
for ($i = 0; $i < count($trace) + 1; $i++) {
$traceCount = count($trace);
for ($i = 0; $i < $traceCount + 1; $i++) {
$frames[] = [
'function' => $trace[$i]['function'] ?? '{main}',
'class' => $trace[$i]['class'] ?? null,
Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Trace/SpanProcessor/BatchSpanProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public function shutdown(): bool
return true;
}

if (null !== $this->exporter) {
$this->forceFlush() && $this->exporter->shutdown();
if (null !== $this->exporter && $this->forceFlush()) {
$this->exporter->shutdown();
}
$this->running = false;

Expand Down

0 comments on commit 015a55f

Please sign in to comment.