fixing some psalm 5 complaints (#1110)
Whilst investigating upgrading to psalm 5, I notice that it generates a lot of new complaints. This fixes the ones that looked legit and require an API change, or were trivial. Does not upgrade to psalm 5 yet, though. That's a bigger job for another day.
This commit is contained in:
parent
73ff5adcb8
commit
1852d514ca
|
@ -34,6 +34,7 @@ $childSpan2 = $tracer->spanBuilder('bar')->startSpan();
|
|||
$childSpan2->end();
|
||||
$childSpan1->end();
|
||||
$rootSpan->end();
|
||||
$rootScope->detach();
|
||||
|
||||
/** @var SpanDataInterface $span */
|
||||
foreach ($storage as $span) {
|
||||
|
|
|
@ -4,9 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace OpenTelemetry\API;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class Signals
|
||||
interface Signals
|
||||
{
|
||||
/** @var string */
|
||||
public const TRACE = 'trace';
|
||||
|
@ -20,11 +18,4 @@ class Signals
|
|||
self::METRICS,
|
||||
self::LOGS,
|
||||
];
|
||||
|
||||
public static function validate(string $signal): void
|
||||
{
|
||||
if (!in_array($signal, self::SIGNALS)) {
|
||||
throw new InvalidArgumentException('Unknown signal: ' . $signal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,26 +7,11 @@ namespace OpenTelemetry\API\Trace;
|
|||
/**
|
||||
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#spankind
|
||||
*/
|
||||
final class SpanKind
|
||||
interface SpanKind
|
||||
{
|
||||
public const KIND_INTERNAL = 0;
|
||||
public const KIND_CLIENT = 1;
|
||||
public const KIND_SERVER = 2;
|
||||
public const KIND_PRODUCER = 3;
|
||||
public const KIND_CONSUMER = 4;
|
||||
|
||||
public static function getChoices(): array
|
||||
{
|
||||
return [
|
||||
self::KIND_INTERNAL,
|
||||
self::KIND_CLIENT,
|
||||
self::KIND_SERVER,
|
||||
self::KIND_PRODUCER,
|
||||
self::KIND_CONSUMER,
|
||||
];
|
||||
}
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,22 +7,9 @@ namespace OpenTelemetry\API\Trace;
|
|||
/**
|
||||
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#set-status
|
||||
*/
|
||||
final class StatusCode
|
||||
interface StatusCode
|
||||
{
|
||||
public const STATUS_UNSET = 'Unset';
|
||||
public const STATUS_OK = 'Ok';
|
||||
public const STATUS_ERROR = 'Error';
|
||||
|
||||
public function getChoices(): array
|
||||
{
|
||||
return [
|
||||
self::STATUS_UNSET,
|
||||
self::STATUS_OK,
|
||||
self::STATUS_ERROR,
|
||||
];
|
||||
}
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OpenTelemetry\Context\Propagation;
|
||||
|
||||
use function array_key_first;
|
||||
use function count;
|
||||
|
||||
final class TextMapPropagator
|
||||
{
|
||||
public static function composite(TextMapPropagatorInterface ...$propagators): TextMapPropagatorInterface
|
||||
{
|
||||
switch (count($propagators)) {
|
||||
case 0:
|
||||
return NoopTextMapPropagator::getInstance();
|
||||
case 1:
|
||||
/** @psalm-suppress PossiblyNullArrayOffset */
|
||||
return $propagators[array_key_first($propagators)];
|
||||
default:
|
||||
return new MultiTextMapPropagator($propagators);
|
||||
}
|
||||
}
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;
|
|||
class OtlpHttpTransportFactory implements TransportFactoryInterface
|
||||
{
|
||||
private const DEFAULT_COMPRESSION = 'none';
|
||||
|
||||
public function create(
|
||||
string $endpoint,
|
||||
string $contentType,
|
||||
|
|
|
@ -71,11 +71,6 @@ final class DependencyResolver implements DependencyResolverInterface
|
|||
return $this->messageFactoryResolver->resolveUriFactory();
|
||||
}
|
||||
|
||||
public function resolveHttpClient(): ClientInterface
|
||||
{
|
||||
return $this->psrClientResolver->resolvePsrClient();
|
||||
}
|
||||
|
||||
public function resolveHttpPlugAsyncClient(): HttpAsyncClient
|
||||
{
|
||||
return $this->httpPlugClientResolver->resolveHttpPlugAsyncClient();
|
||||
|
|
|
@ -57,7 +57,7 @@ final class PsrTransportFactory implements TransportFactoryInterface
|
|||
$endpoint,
|
||||
$contentType,
|
||||
$headers,
|
||||
(array) $compression,
|
||||
PsrUtils::compression($compression),
|
||||
$retryDelay,
|
||||
$maxRetries,
|
||||
);
|
||||
|
|
|
@ -104,6 +104,24 @@ final class PsrUtils
|
|||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an array or CSV of compression types to a list
|
||||
*/
|
||||
public static function compression($compression): array
|
||||
{
|
||||
if (is_array($compression)) {
|
||||
return $compression;
|
||||
}
|
||||
if (!$compression) {
|
||||
return [];
|
||||
}
|
||||
if (strpos($compression, ',') === false) {
|
||||
return [$compression];
|
||||
}
|
||||
|
||||
return array_map('trim', explode(',', $compression));
|
||||
}
|
||||
|
||||
private static function encoder(string $encoding): ?callable
|
||||
{
|
||||
static $encoders;
|
||||
|
|
|
@ -116,7 +116,7 @@ class ScopeTest extends TestCase
|
|||
$scope['key'] = 'value';
|
||||
$scope = $storage->scope();
|
||||
$this->assertNotNull($scope);
|
||||
$this->assertArrayHasKey('key', $scope); /** @phpstan-ignore-line */
|
||||
$this->assertArrayHasKey('key', $scope);
|
||||
$this->assertSame('value', $scope['key']);
|
||||
|
||||
unset($scope['key']);
|
||||
|
|
|
@ -91,4 +91,23 @@ final class PsrUtilsTest extends TestCase
|
|||
|
||||
PsrUtils::decode('', ['invalid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider compressionProvider
|
||||
*/
|
||||
public function test_resolve_compression($input, $expected): void
|
||||
{
|
||||
$this->assertSame($expected, PsrUtils::compression($input));
|
||||
}
|
||||
|
||||
public static function compressionProvider(): array
|
||||
{
|
||||
return [
|
||||
['gzip', ['gzip']],
|
||||
['', []],
|
||||
['gzip,br', ['gzip','br']],
|
||||
['gzip , brotli', ['gzip','brotli']],
|
||||
[['gzip'], ['gzip']],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue