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

deps: Upgrade to PHPStan 2.0 #694

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
"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",
"galbar/jsonpath": "^3.0",
"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": {
Expand Down
7 changes: 4 additions & 3 deletions src/PhpPact/FFI/Model/ArrayData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function getSize(): int
}

/**
* @param array<int, string> $values
* @param string[] $values
*/
public static function createFrom(array $values): ?self
{
Expand All @@ -38,15 +38,16 @@ 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);
if ($item === null) {
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);
Expand Down
1 change: 1 addition & 0 deletions src/PhpPact/Standalone/MockService/MockServerEnvConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct()

$version = $this->parseEnv('PACT_SPECIFICATION_VERSION');
if (!$version) {
/** @var string */
$version = static::DEFAULT_SPECIFICATION_VERSION;
}

Expand Down
4 changes: 1 addition & 3 deletions src/PhpPact/Standalone/StubService/StubServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()}";
Expand Down
17 changes: 7 additions & 10 deletions tests/PhpPact/Consumer/MessageBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -242,14 +240,13 @@ private function getMessage(): Message
}

/**
* @return array<mixed, callable>
* @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);
}
}
8 changes: 4 additions & 4 deletions tests/PhpPact/FFI/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/PhpPact/FFI/Model/ArrayDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/PhpPact/Log/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down