Apply rector Code Quality rules (#743)
* Add rector Code Quality rule * Apply rector Code Quality rule
This commit is contained in:
parent
e3564e2fe9
commit
47ee3e9e80
|
|
@ -15,5 +15,6 @@ return static function (RectorConfig $rectorConfig): void {
|
|||
|
||||
$rectorConfig->sets([
|
||||
SetList::PHP_74,
|
||||
SetList::CODE_QUALITY,
|
||||
]);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ final class Baggage implements BaggageInterface
|
|||
/** @inheritDoc */
|
||||
public function getValue(string $key)
|
||||
{
|
||||
if ($entry = $this->getEntry($key)) {
|
||||
if (($entry = $this->getEntry($key)) !== null) {
|
||||
return $entry->getValue();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,14 +56,14 @@ final class BaggagePropagator implements TextMapPropagatorInterface
|
|||
$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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ final class TraceContextPropagator implements TextMapPropagatorInterface
|
|||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,14 +139,11 @@ class TraceState implements TraceStateInterface
|
|||
$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;
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ final class FiberBoundContextStorage implements ContextStorageInterface, Executi
|
|||
{
|
||||
$this->checkFiberMismatch();
|
||||
|
||||
if (!$scope = $this->storage->scope()) {
|
||||
if (($scope = $this->storage->scope()) === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ final class ArrayAccessGetterSetter implements PropagationGetterInterface, Propa
|
|||
|
||||
foreach ($carrier as $k => $_) {
|
||||
$k = (string) $k;
|
||||
if (!strcasecmp($k, $key)) {
|
||||
if (strcasecmp($k, $key) === 0) {
|
||||
return $k;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ final class SwooleContextStorage implements ContextStorageInterface, ExecutionCo
|
|||
{
|
||||
$this->handler->switchToActiveCoroutine();
|
||||
|
||||
if (!$scope = $this->storage->scope()) {
|
||||
if (($scope = $this->storage->scope()) === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -174,9 +174,7 @@ class SpanConverter implements SpanConverterInterface
|
|||
$tags[$k] = $v;
|
||||
}
|
||||
|
||||
$tags = self::buildTags($tags);
|
||||
|
||||
return $tags;
|
||||
return self::buildTags($tags);
|
||||
}
|
||||
|
||||
private static function buildTags(array $tagPairs): array
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class TagFactory
|
|||
]);
|
||||
}
|
||||
|
||||
if (is_integer($value)) {
|
||||
if (is_int($value)) {
|
||||
return new Tag([
|
||||
'key' => $key,
|
||||
'vType' => TagType::LONG,
|
||||
|
|
@ -67,7 +67,7 @@ class TagFactory
|
|||
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
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class SpanConverter implements SpanConverterInterface
|
|||
$instrumentationScope->getAttributes()->getDroppedAttributesCount(),
|
||||
]);
|
||||
|
||||
if (!$pResourceSpans = $resourceSpans[$resourceId] ?? null) {
|
||||
if (($pResourceSpans = $resourceSpans[$resourceId] ?? null) === null) {
|
||||
/** @psalm-suppress InvalidArgument */
|
||||
$pExportTraceServiceRequest->getResourceSpans()[]
|
||||
= $resourceSpans[$resourceId]
|
||||
|
|
@ -64,7 +64,7 @@ class SpanConverter implements SpanConverterInterface
|
|||
= $this->convertResourceSpans($resource);
|
||||
}
|
||||
|
||||
if (!$pScopeSpans = $scopeSpans[$resourceId][$instrumentationScopeId] ?? null) {
|
||||
if (($pScopeSpans = $scopeSpans[$resourceId][$instrumentationScopeId] ?? null) === null) {
|
||||
/** @psalm-suppress InvalidArgument */
|
||||
$pResourceSpans->getScopeSpans()[]
|
||||
= $scopeSpans[$resourceId][$instrumentationScopeId]
|
||||
|
|
@ -138,7 +138,7 @@ class SpanConverter implements SpanConverterInterface
|
|||
$result->setBoolValue($value);
|
||||
|
||||
break;
|
||||
case is_double($value):
|
||||
case is_float($value):
|
||||
$result->setDoubleValue($value);
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ class Exporter implements SpanExporterInterface
|
|||
|
||||
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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class SpanConverter implements SpanConverterInterface
|
|||
// 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
|
||||
|
|
@ -169,12 +169,10 @@ class SpanConverter implements SpanConverterInterface
|
|||
|
||||
$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
|
||||
|
|
@ -184,7 +182,7 @@ class SpanConverter implements SpanConverterInterface
|
|||
}
|
||||
|
||||
$attributesAsJson = json_encode($event->getAttributes()->toArray());
|
||||
if (($attributesAsJson === false) || (strlen($attributesAsJson) === 0)) {
|
||||
if (($attributesAsJson === false) || ($attributesAsJson === '')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class SpanConverter implements SpanConverterInterface
|
|||
// 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
|
||||
|
|
|
|||
|
|
@ -132,7 +132,8 @@ final class StackTraceFormatter
|
|||
{
|
||||
$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,
|
||||
|
|
|
|||
|
|
@ -119,8 +119,8 @@ class BatchSpanProcessor implements SpanProcessorInterface
|
|||
return true;
|
||||
}
|
||||
|
||||
if (null !== $this->exporter) {
|
||||
$this->forceFlush() && $this->exporter->shutdown();
|
||||
if (null !== $this->exporter && $this->forceFlush()) {
|
||||
$this->exporter->shutdown();
|
||||
}
|
||||
$this->running = false;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue