From f1eb9afb481efa850974057baf6b3e9d53996cf5 Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Sat, 23 Nov 2024 19:46:09 +0700 Subject: [PATCH] deps: Upgrade to PHPStan 2.0 --- composer.json | 4 ++-- src/PhpPact/FFI/Model/ArrayData.php | 7 ++++--- .../MockService/MockServerEnvConfig.php | 1 + .../Standalone/StubService/StubServer.php | 4 +--- tests/PhpPact/Consumer/MessageBuilderTest.php | 17 +++++++---------- tests/PhpPact/FFI/ClientTest.php | 8 ++++---- tests/PhpPact/FFI/Model/ArrayDataTest.php | 2 +- tests/PhpPact/Log/LoggerTest.php | 1 + 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 8d5ec29e..e2b3cfad 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "roave/security-advisories": "dev-latest", "friendsofphp/php-cs-fixer": "^3.0", "php-amqplib/php-amqplib": "^3.0", - "phpstan/phpstan": "^1.9", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^10.1.0|^11.0", "guzzlehttp/guzzle": "^7.8", "behat/behat": "^3.13", @@ -40,7 +40,7 @@ "ramsey/uuid": "^4.7", "pact-foundation/example-protobuf-sync-message-provider": "@dev", "webonyx/graphql-php": "^15.14", - "rector/rector": "^1.2", + "rector/rector": "dev-main as 2.0", "clue/framework-x": "^0.16.0" }, "autoload": { diff --git a/src/PhpPact/FFI/Model/ArrayData.php b/src/PhpPact/FFI/Model/ArrayData.php index 93df1d7a..06632509 100644 --- a/src/PhpPact/FFI/Model/ArrayData.php +++ b/src/PhpPact/FFI/Model/ArrayData.php @@ -25,7 +25,7 @@ public function getSize(): int } /** - * @param array $values + * @param string[] $values */ public static function createFrom(array $values): ?self { @@ -38,7 +38,8 @@ public static function createFrom(array $values): ?self if ($items === null) { throw new CDataNotCreatedException(); } - foreach ($values as $index => $value) { + $index = 0; + foreach ($values as $value) { $length = \strlen($value); $itemSize = $length + 1; $item = FFI::new("char[{$itemSize}]", false); @@ -46,7 +47,7 @@ public static function createFrom(array $values): ?self throw new CDataNotCreatedException(); } FFI::memcpy($item, $value, $length); - $items[$index] = $item; // @phpstan-ignore-line + $items[$index++] = $item; // @phpstan-ignore-line } return new self($items, $size); diff --git a/src/PhpPact/Standalone/MockService/MockServerEnvConfig.php b/src/PhpPact/Standalone/MockService/MockServerEnvConfig.php index 645668b1..be2c773a 100644 --- a/src/PhpPact/Standalone/MockService/MockServerEnvConfig.php +++ b/src/PhpPact/Standalone/MockService/MockServerEnvConfig.php @@ -36,6 +36,7 @@ public function __construct() $version = $this->parseEnv('PACT_SPECIFICATION_VERSION'); if (!$version) { + /** @var string */ $version = static::DEFAULT_SPECIFICATION_VERSION; } diff --git a/src/PhpPact/Standalone/StubService/StubServer.php b/src/PhpPact/Standalone/StubService/StubServer.php index 84dd0400..8eb63215 100644 --- a/src/PhpPact/Standalone/StubService/StubServer.php +++ b/src/PhpPact/Standalone/StubService/StubServer.php @@ -94,9 +94,7 @@ private function getArguments(): array $results[] = "--loglevel={$this->config->getLogLevel()}"; } - if ($this->config->getPort() !== null) { - $results[] = "--port={$this->config->getPort()}"; - } + $results[] = "--port={$this->config->getPort()}"; if ($this->config->getProviderState() !== null) { $results[] = "--provider-state={$this->config->getProviderState()}"; diff --git a/tests/PhpPact/Consumer/MessageBuilderTest.php b/tests/PhpPact/Consumer/MessageBuilderTest.php index 01dd497a..e5631440 100644 --- a/tests/PhpPact/Consumer/MessageBuilderTest.php +++ b/tests/PhpPact/Consumer/MessageBuilderTest.php @@ -135,8 +135,7 @@ public function testSetSingleCallback(): void foreach ($callbacks as $callback) { $this->assertSame($this->builder, $this->builder->setCallback($callback)); } - $builderCallbacks = $this->getCallbacks(); - $this->assertSame([end($callbacks)], $builderCallbacks); + $this->assertCallbacks([end($callbacks)]); } public function testSetMultipleCallbacks(): void @@ -150,8 +149,7 @@ public function testSetMultipleCallbacks(): void foreach ($callbacks as $description => $callback) { $this->assertSame($this->builder, $this->builder->setCallback($callback, $description)); } - $builderCallbacks = $this->getCallbacks(); - $this->assertSame($callbacks, $builderCallbacks); + $this->assertCallbacks($callbacks); } public function testReify(): void @@ -242,14 +240,13 @@ private function getMessage(): Message } /** - * @return array + * @param callable[] $expectedCallbacks */ - private function getCallbacks(): array + private function assertCallbacks(array $expectedCallbacks): void { $reflection = new ReflectionProperty($this->builder, 'callback'); - $callback = $reflection->getValue($this->builder); - $this->assertIsArray($callback); - - return $callback; + $callbacks = $reflection->getValue($this->builder); + $this->assertIsArray($callbacks); + $this->assertSame($expectedCallbacks, $callbacks); } } diff --git a/tests/PhpPact/FFI/ClientTest.php b/tests/PhpPact/FFI/ClientTest.php index b91c3cf3..45b09bc9 100644 --- a/tests/PhpPact/FFI/ClientTest.php +++ b/tests/PhpPact/FFI/ClientTest.php @@ -64,19 +64,19 @@ public function testAddTextComment(): void public function testNewInteraction(): void { $result = $this->client->newInteraction(1, 'test'); - $this->assertIsInt($result); + $this->assertNotEmpty($result); } public function testNewMessageInteraction(): void { $result = $this->client->newMessageInteraction(1, 'test'); - $this->assertIsInt($result); + $this->assertNotEmpty($result); } public function testNewSyncMessageInteraction(): void { $result = $this->client->newSyncMessageInteraction(1, 'test'); - $this->assertIsInt($result); + $this->assertNotEmpty($result); } public function testGiven(): void @@ -130,7 +130,7 @@ public function testFreePactHandle(): void public function testNewPact(): void { $result = $this->client->newPact('consumer', 'provider'); - $this->assertIsInt($result); + $this->assertNotEmpty($result); $this->client->freePactHandle($result); } diff --git a/tests/PhpPact/FFI/Model/ArrayDataTest.php b/tests/PhpPact/FFI/Model/ArrayDataTest.php index 3d4e2ec9..4cf15547 100644 --- a/tests/PhpPact/FFI/Model/ArrayDataTest.php +++ b/tests/PhpPact/FFI/Model/ArrayDataTest.php @@ -20,7 +20,7 @@ public function testCreateFromArray(): void $this->assertInstanceOf(ArrayData::class, $arrayData); $this->assertSame(count($branches), $arrayData->getSize()); foreach ($branches as $index => $branch) { - // @phpstan-ignore offsetAccess.nonOffsetAccessible + // @phpstan-ignore offsetAccess.nonOffsetAccessible,argument.type $this->assertSame($branch, FFI::string($arrayData->getItems()[$index])); } } diff --git a/tests/PhpPact/Log/LoggerTest.php b/tests/PhpPact/Log/LoggerTest.php index 7c55bd5c..0053ba19 100644 --- a/tests/PhpPact/Log/LoggerTest.php +++ b/tests/PhpPact/Log/LoggerTest.php @@ -67,6 +67,7 @@ public function testClone(): void { $this->expectException(Error::class); $this->expectExceptionMessage('Call to protected PhpPact\Log\Logger::__clone()'); + // @phpstan-ignore expr.resultUnused clone $this->logger; }