From ca40b5312122e73b16fc7d008d98b7667991377e Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 23 Jun 2023 01:42:57 +0200 Subject: [PATCH 1/2] Improve and fix the generic types for the ResultMockFactory --- src/Core/src/Test/ResultMockFactory.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Core/src/Test/ResultMockFactory.php b/src/Core/src/Test/ResultMockFactory.php index c4a827cbc..777c40e49 100644 --- a/src/Core/src/Test/ResultMockFactory.php +++ b/src/Core/src/Test/ResultMockFactory.php @@ -26,11 +26,11 @@ class ResultMockFactory * ResultMockFactory::createFailing(SendEmailResponse::class, 400, 'invalid value'); * * - * @template T + * @template T of Result * * @psalm-param class-string $class * - * @return Result|T + * @return T */ public static function createFailing( string $class, @@ -61,11 +61,11 @@ public static function createFailing( * ResultMockFactory::create(SendEmailResponse::class, ['MessageId'=>'foo123']); * * - * @template T + * @template T of Result * * @psalm-param class-string $class * - * @return Result|T + * @return T */ public static function create(string $class, array $data = []) { @@ -124,11 +124,11 @@ public static function create(string $class, array $data = []) /** * Instantiate a Waiter class with a final state. * - * @template T + * @template T of Waiter * * @psalm-param class-string $class * - * @return Result|T + * @return T */ public static function waiter(string $class, string $finalState) { From e5706d87a26ab04c108097f7b6d83df55b00ad92 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 23 Jun 2023 11:02:15 +0200 Subject: [PATCH 2/2] Add inline var comments to overcome bad Psalm type inference --- src/Core/src/Test/ResultMockFactory.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Core/src/Test/ResultMockFactory.php b/src/Core/src/Test/ResultMockFactory.php index 777c40e49..9f7342814 100644 --- a/src/Core/src/Test/ResultMockFactory.php +++ b/src/Core/src/Test/ResultMockFactory.php @@ -49,6 +49,7 @@ public static function createFailing( $client = new MockHttpClient($httpResponse); $response = new Response($client->request('POST', 'http://localhost'), $client, new NullLogger()); + /** @psalm-var \ReflectionClass $reflectionClass */ $reflectionClass = new \ReflectionClass($class); return $reflectionClass->newInstance($response); @@ -83,6 +84,7 @@ public static function create(string $class, array $data = []) $initializedProperty = $reflectionClass->getProperty('initialized'); $initializedProperty->setAccessible(true); + /** @psalm-var \ReflectionClass $reflectionClass */ $reflectionClass = new \ReflectionClass($class); $object = $reflectionClass->newInstance($response); if (Result::class !== $class) { @@ -152,6 +154,7 @@ public static function waiter(string $class, string $finalState) $propertyState = $reflectionClass->getProperty('finalState'); $propertyState->setAccessible(true); + /** @psalm-var \ReflectionClass $reflectionClass */ $reflectionClass = new \ReflectionClass($class); $result = $reflectionClass->newInstanceWithoutConstructor(); $propertyResponse->setValue($result, $response);