Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade psalm to v5 #1246

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.6",
"psalm/plugin-mockery": "^0.11",
"psalm/plugin-mockery": "^1",
"psalm/plugin-phpunit": "^0.18.4",
"psalm/psalm": "^4.30",
"psalm/psalm": "^5",
"qossmic/deptrac-shim": "^0.24 || ^1",
"rector/rector": ">=0.15.20",
"rector/rector": "^1",
"symfony/http-client": "^5.2",
"symfony/yaml": "^6 || ^5"
},
Expand Down
1 change: 1 addition & 0 deletions examples/autoload_sdk_with_custom_transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* create a transport factory to override the default grpc one (for both traces and metrics):
* @psalm-suppress InvalidReturnType
* @psalm-suppress InvalidReturnStatement
* @psalm-suppress MissingTemplateParam
*/
$factory = new class() implements \OpenTelemetry\SDK\Common\Export\TransportFactoryInterface {
public function create(string $endpoint, string $contentType, array $headers = [], $compression = null, float $timeout = 10., int $retryDelay = 100, int $maxRetries = 3, ?string $cacert = null, ?string $cert = null, ?string $key = null): \OpenTelemetry\SDK\Common\Export\TransportInterface
Expand Down
3 changes: 2 additions & 1 deletion examples/traces/exporters/otlp_http_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

require __DIR__ . '/../../../vendor/autoload.php';

use OpenTelemetry\Contrib\Otlp\ContentTypes;
use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory;
use OpenTelemetry\Contrib\Otlp\SpanExporter;
use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor;
use OpenTelemetry\SDK\Trace\TracerProvider;

$transport = (new OtlpHttpTransportFactory())->create('http://collector:4318/v1/traces', 'application/json');
$transport = (new OtlpHttpTransportFactory())->create('http://collector:4318/v1/traces', ContentTypes::JSON);
$exporter = new SpanExporter($transport);

echo 'Starting OTLP+json example';
Expand Down
7 changes: 7 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<psalm
errorLevel="3"
cacheDirectory="var/cache/psalm"
findUnusedBaselineEntry="false"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
Expand All @@ -24,5 +26,10 @@
<referencedClass name="GMP" />
</errorLevel>
</UndefinedClass>
<ArgumentTypeCoercion>
<errorLevel type="suppress">
<directory name="./examples" />
</errorLevel>
</ArgumentTypeCoercion>
</issueHandlers>
</psalm>
1 change: 1 addition & 0 deletions src/API/Baggage/Propagation/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function parseInto(BaggageBuilderInterface $baggageBuilder): void
$metadata = null;
}

/** @psalm-suppress PossiblyUndefinedArrayOffset */
[$key, $value] = explode(self::EQUALS, $keyValue, 2);

$key = urldecode($key);
Expand Down
4 changes: 4 additions & 0 deletions src/API/Behavior/Internal/LogWriter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public static function format($level, string $message, array $context): string
} else {
//get calling location, skipping over trait, formatter etc
$caller = debug_backtrace()[3];
/**
* @psalm-suppress PossiblyNullArgument
* @psalm-suppress PossiblyUndefinedArrayOffset
*/
$message = sprintf(
'OpenTelemetry: [%s] %s in %s(%s)',
$level,
Expand Down
1 change: 1 addition & 0 deletions src/Context/ContextKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* @internal
* @psalm-suppress MissingTemplateParam
*/
final class ContextKey implements ContextKeyInterface
{
Expand Down
3 changes: 3 additions & 0 deletions src/Context/ContextStorageScopeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use ArrayAccess;

/**
* @psalm-suppress MissingTemplateParam
*/
interface ContextStorageScopeInterface extends ScopeInterface, ArrayAccess
{
/**
Expand Down
1 change: 1 addition & 0 deletions src/Contrib/Grpc/GrpcTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ final class GrpcTransportFactory implements TransportFactoryInterface
* @psalm-return TransportInterface<"application/x-protobuf">
* @psalm-suppress MoreSpecificImplementedParamType
* @psalm-suppress ImplementedReturnTypeMismatch
* @psalm-suppress NoValue
*/
public function create(
string $endpoint,
Expand Down
3 changes: 3 additions & 0 deletions src/Contrib/Otlp/ContentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace OpenTelemetry\Contrib\Otlp;

/**
* @todo enum (php >= 8.1)
*/
interface ContentTypes
{
public const PROTOBUF = 'application/x-protobuf';
Expand Down
3 changes: 3 additions & 0 deletions src/SDK/Common/Attribute/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use IteratorAggregate;
use Traversable;

/**
* @psalm-suppress MissingTemplateParam
*/
final class Attributes implements AttributesInterface, IteratorAggregate
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/SDK/Common/Attribute/AttributesBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use ArrayAccess;

/**
* @psalm-suppress MissingTemplateParam
*/
interface AttributesBuilderInterface extends ArrayAccess
{
public function build(): AttributesInterface;
Expand Down
3 changes: 3 additions & 0 deletions src/SDK/Common/Attribute/AttributesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Countable;
use Traversable;

/**
* @psalm-suppress MissingTemplateParam
*/
interface AttributesInterface extends Traversable, Countable
{
public function has(string $name): bool;
Expand Down
1 change: 1 addition & 0 deletions src/SDK/Common/Configuration/Parser/MapParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function parse($value): array
foreach (explode(self::VARIABLE_SEPARATOR, $value) as $pair) {
self::validateKeyValuePair($pair);

/** @psalm-suppress PossiblyUndefinedArrayOffset */
[$key, $value] = explode(self::KEY_VALUE_SEPARATOR, $pair, 2);
$result[trim($key)] = trim($value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Common/Exception/StackTraceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ private static function writeNewline(string &$s, int $indent = 0): void

/**
* @psalm-return Frames
*
* @psalm-suppress PossiblyUndefinedArrayOffset
* @psalm-suppress InvalidArrayOffset
*/
private static function frames(Throwable $e): array
{
Expand Down
6 changes: 6 additions & 0 deletions src/SDK/Common/Export/Http/PsrTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function contentType(): string
return $this->contentType;
}

/**
* @psalm-suppress ArgumentTypeCoercion
*/
public function send(string $payload, ?CancellationInterface $cancellation = null): FutureInterface
{
if ($this->closed) {
Expand Down Expand Up @@ -118,6 +121,9 @@ public function send(string $payload, ?CancellationInterface $cancellation = nul
return new CompletedFuture($body);
}

/**
* @return list<string>
*/
private static function parseContentEncoding(ResponseInterface $response): array
{
$encodings = [];
Expand Down
1 change: 1 addition & 0 deletions src/SDK/Common/Export/Http/PsrUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static function encode(string $value, array $encodings, ?array &$appliedE

/**
* @param list<string> $encodings
* @psalm-suppress InvalidArrayOffset
*/
public static function decode(string $value, array $encodings): string
{
Expand Down
3 changes: 3 additions & 0 deletions src/SDK/Common/Future/ErrorFuture.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Closure;
use Throwable;

/**
* @psalm-suppress MissingTemplateParam
*/
final class ErrorFuture implements FutureInterface
{
public function __construct(private Throwable $throwable)
Expand Down
5 changes: 4 additions & 1 deletion src/SDK/Common/Util/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ function weaken(Closure $closure, ?object &$target = null): Closure

static $placeholder;
$placeholder ??= new stdClass();
/** @psalm-suppress PossiblyNullReference */
$closure = $closure->bindTo($placeholder);

$ref = WeakReference::create($target);

/** @psalm-suppress PossiblyInvalidFunctionCall */
/**
* @psalm-suppress all
*/
return $scope && $target::class === $scope->name && !$scope->isInternal()
? static fn (...$args) => ($obj = $ref->get()) ? $closure->call($obj, ...$args) : null
: static fn (...$args) => ($obj = $ref->get()) ? $closure->bindTo($obj)(...$args) : null;
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Logs/Exporter/InMemoryExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(?ArrayObject $storage = null)
public function export(iterable $batch, ?CancellationInterface $cancellation = null): FutureInterface
{
foreach ($batch as $record) {
$this->storage[] = $record;
$this->storage->append($record);
}

return new CompletedFuture(true);
Expand Down
3 changes: 3 additions & 0 deletions src/SDK/Metrics/View/CriteriaViewRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public function register(SelectionCriteriaInterface $criteria, ViewTemplate $vie
$this->views[] = $view;
}

/**
* @todo is null the best return type here? what about empty array or exception?
*/
public function find(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): ?iterable
{
$views = $this->generateViews($instrument, $instrumentationScope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ final class InstrumentNameCriteria implements SelectionCriteriaInterface
{
private string $pattern;

/**
* @param non-empty-string $name
*/
public function __construct(string $name)
{
$this->pattern = sprintf('/^%s$/', strtr(preg_quote($name, '/'), ['\\?' => '.', '\\*' => '.*']));
}

/**
* @psalm-suppress ArgumentTypeCoercion
*/
public function accepts(Instrument $instrument, InstrumentationScopeInterface $instrumentationScope): bool
{
return (bool) preg_match($this->pattern, $instrument->name);
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Propagation/PropagatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function create(): TextMapPropagatorInterface
}

/**
* @return array<TextMapPropagatorInterface>
* @return list<TextMapPropagatorInterface>
*/
private function buildPropagators(array $names): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Trace/SpanExporter/InMemoryExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(?ArrayObject $storage = null)
protected function doExport(iterable $spans): bool
{
foreach ($spans as $span) {
$this->storage[] = $span;
$this->storage->append($span);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Trace/TracerProviderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TracerProviderBuilder
{
// @var array<SpanProcessorInterface>
/** @var list<SpanProcessorInterface> */
private ?array $spanProcessors = [];
private ?ResourceInfo $resource = null;
private ?SamplerInterface $sampler = null;
Expand Down
3 changes: 3 additions & 0 deletions tests/Benchmark/OtlpBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function setUpNoExporter(): void
$this->tracer = $provider->getTracer('io.opentelemetry.contrib.php');
}

/**
* @psalm-suppress MissingTemplateParam
*/
private function createTransport(string $contentType): TransportInterface
{
return new class($contentType) implements TransportInterface {
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/API/Baggage/Propagation/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public static function invalidHeaderProvider(): array
'empty key' => ['=value'],
'key with invalid char' => ['@foo=bar'],
'value with invalid char' => ['foo="bar"'],
'missing value' => ['key1='],
];
}
}
Loading
Loading