Skip to content

Commit 1852d51

Browse files
authored
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.
1 parent 73ff5ad commit 1852d51

File tree

11 files changed

+44
-75
lines changed

11 files changed

+44
-75
lines changed

examples/traces/exporters/in_memory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
$childSpan2->end();
3535
$childSpan1->end();
3636
$rootSpan->end();
37+
$rootScope->detach();
3738

3839
/** @var SpanDataInterface $span */
3940
foreach ($storage as $span) {

src/API/Signals.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
namespace OpenTelemetry\API;
66

7-
use InvalidArgumentException;
8-
9-
class Signals
7+
interface Signals
108
{
119
/** @var string */
1210
public const TRACE = 'trace';
@@ -20,11 +18,4 @@ class Signals
2018
self::METRICS,
2119
self::LOGS,
2220
];
23-
24-
public static function validate(string $signal): void
25-
{
26-
if (!in_array($signal, self::SIGNALS)) {
27-
throw new InvalidArgumentException('Unknown signal: ' . $signal);
28-
}
29-
}
3021
}

src/API/Trace/SpanKind.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,11 @@
77
/**
88
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#spankind
99
*/
10-
final class SpanKind
10+
interface SpanKind
1111
{
1212
public const KIND_INTERNAL = 0;
1313
public const KIND_CLIENT = 1;
1414
public const KIND_SERVER = 2;
1515
public const KIND_PRODUCER = 3;
1616
public const KIND_CONSUMER = 4;
17-
18-
public static function getChoices(): array
19-
{
20-
return [
21-
self::KIND_INTERNAL,
22-
self::KIND_CLIENT,
23-
self::KIND_SERVER,
24-
self::KIND_PRODUCER,
25-
self::KIND_CONSUMER,
26-
];
27-
}
28-
29-
private function __construct()
30-
{
31-
}
3217
}

src/API/Trace/StatusCode.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,9 @@
77
/**
88
* @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.6.1/specification/trace/api.md#set-status
99
*/
10-
final class StatusCode
10+
interface StatusCode
1111
{
1212
public const STATUS_UNSET = 'Unset';
1313
public const STATUS_OK = 'Ok';
1414
public const STATUS_ERROR = 'Error';
15-
16-
public function getChoices(): array
17-
{
18-
return [
19-
self::STATUS_UNSET,
20-
self::STATUS_OK,
21-
self::STATUS_ERROR,
22-
];
23-
}
24-
25-
private function __construct()
26-
{
27-
}
2815
}

src/Context/Propagation/TextMapPropagator.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Contrib/Otlp/OtlpHttpTransportFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class OtlpHttpTransportFactory implements TransportFactoryInterface
1212
{
1313
private const DEFAULT_COMPRESSION = 'none';
14+
1415
public function create(
1516
string $endpoint,
1617
string $contentType,

src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ public function resolveUriFactory(): UriFactoryInterface
7171
return $this->messageFactoryResolver->resolveUriFactory();
7272
}
7373

74-
public function resolveHttpClient(): ClientInterface
75-
{
76-
return $this->psrClientResolver->resolvePsrClient();
77-
}
78-
7974
public function resolveHttpPlugAsyncClient(): HttpAsyncClient
8075
{
8176
return $this->httpPlugClientResolver->resolveHttpPlugAsyncClient();

src/SDK/Common/Export/Http/PsrTransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function create(
5757
$endpoint,
5858
$contentType,
5959
$headers,
60-
(array) $compression,
60+
PsrUtils::compression($compression),
6161
$retryDelay,
6262
$maxRetries,
6363
);

src/SDK/Common/Export/Http/PsrUtils.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,24 @@ public static function decode(string $value, array $encodings): string
104104
return $value;
105105
}
106106

107+
/**
108+
* Resolve an array or CSV of compression types to a list
109+
*/
110+
public static function compression($compression): array
111+
{
112+
if (is_array($compression)) {
113+
return $compression;
114+
}
115+
if (!$compression) {
116+
return [];
117+
}
118+
if (strpos($compression, ',') === false) {
119+
return [$compression];
120+
}
121+
122+
return array_map('trim', explode(',', $compression));
123+
}
124+
107125
private static function encoder(string $encoding): ?callable
108126
{
109127
static $encoders;

tests/Unit/Context/ScopeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function test_scope_local_storage_is_preserved_between_attach_and_scope()
116116
$scope['key'] = 'value';
117117
$scope = $storage->scope();
118118
$this->assertNotNull($scope);
119-
$this->assertArrayHasKey('key', $scope); /** @phpstan-ignore-line */
119+
$this->assertArrayHasKey('key', $scope);
120120
$this->assertSame('value', $scope['key']);
121121

122122
unset($scope['key']);

0 commit comments

Comments
 (0)