From afdf26e0d88bd78b58000e95da5134fcec3bbc08 Mon Sep 17 00:00:00 2001 From: "tien.xuan.vo" Date: Tue, 24 Sep 2024 15:51:04 +0700 Subject: [PATCH] refactor: Install rector and auto refactor --- .../public/provider-states/index.php | 2 +- composer.json | 4 +++- example/message/consumer/src/receive.php | 2 +- rector.php | 16 ++++++++++++++++ .../MockServer/MockServerEnvConfigTest.php | 16 ++++++++-------- 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 rector.php diff --git a/compatibility-suite/public/provider-states/index.php b/compatibility-suite/public/provider-states/index.php index b7de797b..9a083cbe 100644 --- a/compatibility-suite/public/provider-states/index.php +++ b/compatibility-suite/public/provider-states/index.php @@ -59,7 +59,7 @@ $app->post('/pact-change-state', $stateChangeHandler); -$app->post('/failed-pact-change-state', function (Request $request, Response $response) use ($stateChangeHandler) { +$app->post('/failed-pact-change-state', function (Request $request, Response $response) use ($stateChangeHandler): void { $stateChangeHandler($request, $response); throw new \Exception('Cant do it'); diff --git a/composer.json b/composer.json index c5a14ca9..d1ee39f0 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,8 @@ "galbar/jsonpath": "^3.0", "ramsey/uuid": "^4.7", "pact-foundation/example-protobuf-sync-message-provider": "@dev", - "webonyx/graphql-php": "^15.14" + "webonyx/graphql-php": "^15.14", + "rector/rector": "^1.2" }, "autoload": { "psr-4": { @@ -60,6 +61,7 @@ "fix": "php-cs-fixer fix", "test": "phpunit --no-coverage", "check-compatibility": "behat", + "refactor": "rector", "run-examples": [ "composer run-example:binary", "composer run-example:csv", diff --git a/example/message/consumer/src/receive.php b/example/message/consumer/src/receive.php index 1c04e868..e236617a 100644 --- a/example/message/consumer/src/receive.php +++ b/example/message/consumer/src/receive.php @@ -12,7 +12,7 @@ $channel->queue_declare('myKey', false, false, false, false); echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; -$callback = function ($msg) { +$callback = function ($msg): void { // process that invokes the use of the message $processor = new MessageConsumer\ExampleMessageConsumer(); $processor->processMessage($msg->body); diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..4d629d9c --- /dev/null +++ b/rector.php @@ -0,0 +1,16 @@ +withPaths([ + __DIR__ . '/compatibility-suite', + __DIR__ . '/example', + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withTypeCoverageLevel(0); diff --git a/tests/PhpPact/Standalone/MockServer/MockServerEnvConfigTest.php b/tests/PhpPact/Standalone/MockServer/MockServerEnvConfigTest.php index 5a054b80..11f2f173 100644 --- a/tests/PhpPact/Standalone/MockServer/MockServerEnvConfigTest.php +++ b/tests/PhpPact/Standalone/MockServer/MockServerEnvConfigTest.php @@ -13,7 +13,7 @@ class MockServerEnvConfigTest extends TestCase #[TestWith(['PACT_MOCK_SERVER_HOST=example.test', 'example.test'])] public function testHost(string $assignment, string $host): void { - $this->preserveEnv('PACT_MOCK_SERVER_PORT', $assignment, function () use ($host) { + $this->preserveEnv('PACT_MOCK_SERVER_PORT', $assignment, function () use ($host): void { $config = new MockServerEnvConfig(); $this->assertSame($host, $config->getHost()); }); @@ -23,7 +23,7 @@ public function testHost(string $assignment, string $host): void #[TestWith(['PACT_MOCK_SERVER_PORT=123', 123])] public function testPort(string $assignment, int $port): void { - $this->preserveEnv('PACT_MOCK_SERVER_PORT', $assignment, function () use ($port) { + $this->preserveEnv('PACT_MOCK_SERVER_PORT', $assignment, function () use ($port): void { $config = new MockServerEnvConfig(); $this->assertSame($port, $config->getPort()); }); @@ -33,7 +33,7 @@ public function testPort(string $assignment, int $port): void #[TestWith(['PACT_CONSUMER_NAME=consumer', 'consumer'])] public function testConsumer(string $assignment, ?string $consumer): void { - $this->preserveEnv('PACT_CONSUMER_NAME', $assignment, function () use ($consumer) { + $this->preserveEnv('PACT_CONSUMER_NAME', $assignment, function () use ($consumer): void { if (!$consumer) { $this->expectException(MissingEnvVariableException::class); $this->expectExceptionMessage('Please provide required environmental variable PACT_CONSUMER_NAME!'); @@ -47,7 +47,7 @@ public function testConsumer(string $assignment, ?string $consumer): void #[TestWith(['PACT_PROVIDER_NAME=provider', 'provider'])] public function testProvider(string $assignment, ?string $provider): void { - $this->preserveEnv('PACT_PROVIDER_NAME', $assignment, function () use ($provider) { + $this->preserveEnv('PACT_PROVIDER_NAME', $assignment, function () use ($provider): void { if (!$provider) { $this->expectException(MissingEnvVariableException::class); $this->expectExceptionMessage('Please provide required environmental variable PACT_PROVIDER_NAME!'); @@ -61,7 +61,7 @@ public function testProvider(string $assignment, ?string $provider): void #[TestWith(['PACT_OUTPUT_DIR=/path/to/pact/dir', '/path/to/pact/dir'])] public function testPactDir(string $assignment, ?string $pactDir): void { - $this->preserveEnv('PACT_OUTPUT_DIR', $assignment, function () use ($pactDir) { + $this->preserveEnv('PACT_OUTPUT_DIR', $assignment, function () use ($pactDir): void { $pactDir ??= \sys_get_temp_dir(); $config = new MockServerEnvConfig(); $this->assertSame($pactDir, $config->getPactDir()); @@ -72,7 +72,7 @@ public function testPactDir(string $assignment, ?string $pactDir): void #[TestWith(['PACT_LOG=/path/to/log/dir', '/path/to/log/dir'])] public function testLog(string $assignment, ?string $logDir): void { - $this->preserveEnv('PACT_LOG', $assignment, function () use ($logDir) { + $this->preserveEnv('PACT_LOG', $assignment, function () use ($logDir): void { $config = new MockServerEnvConfig(); $this->assertSame($logDir, $config->getLog()); }); @@ -82,7 +82,7 @@ public function testLog(string $assignment, ?string $logDir): void #[TestWith(['PACT_LOGLEVEL=trace', 'TRACE'])] public function testLogLevel(string $assignment, ?string $logLevel): void { - $this->preserveEnv('PACT_LOGLEVEL', $assignment, function () use ($logLevel) { + $this->preserveEnv('PACT_LOGLEVEL', $assignment, function () use ($logLevel): void { $config = new MockServerEnvConfig(); $this->assertSame($logLevel, $config->getLogLevel()); }); @@ -92,7 +92,7 @@ public function testLogLevel(string $assignment, ?string $logLevel): void #[TestWith(['PACT_SPECIFICATION_VERSION=1.1.0', '1.1.0'])] public function testPactSpecificationVersion(string $assignment, ?string $specificationVersion): void { - $this->preserveEnv('PACT_SPECIFICATION_VERSION', $assignment, function () use ($specificationVersion) { + $this->preserveEnv('PACT_SPECIFICATION_VERSION', $assignment, function () use ($specificationVersion): void { $config = new MockServerEnvConfig(); $this->assertSame($specificationVersion, $config->getPactSpecificationVersion()); });