From 37d719ed67feff858777a74b5b8474eb51e9697e Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Sun, 16 Jun 2019 15:20:49 +0200 Subject: [PATCH] Fix readability for object-like types when running `psalter` (#1708) * chore: update tests * fix: better readability for object-like types * test: add tests for nested array return type * Improve spacing --- src/Psalm/Type/Atomic/ObjectLike.php | 6 +- .../ReturnTypeManipulationTest.php | 58 ++++++++++++++++--- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/Psalm/Type/Atomic/ObjectLike.php b/src/Psalm/Type/Atomic/ObjectLike.php index 83af56b83f0..996a9cd3797 100644 --- a/src/Psalm/Type/Atomic/ObjectLike.php +++ b/src/Psalm/Type/Atomic/ObjectLike.php @@ -62,7 +62,7 @@ public function __toString() * @return string */ function ($name, Union $type) { - return $name . ($type->possibly_undefined ? '?' : '') . ':' . $type; + return $name . ($type->possibly_undefined ? '?' : '') . ': ' . $type; }, array_keys($this->properties), $this->properties @@ -85,7 +85,7 @@ public function getId() * @return string */ function ($name, Union $type) { - return $name . ($type->possibly_undefined ? '?' : '') . ':' . $type->getId(); + return $name . ($type->possibly_undefined ? '?' : '') . ': ' . $type->getId(); }, array_keys($this->properties), $this->properties @@ -134,7 +134,7 @@ function ( $this_class, $use_phpdoc_format ) { - return $name . ($type->possibly_undefined ? '?' : '') . ':' . $type->toNamespacedString( + return $name . ($type->possibly_undefined ? '?' : '') . ': ' . $type->toNamespacedString( $namespace, $aliased_classes, $this_class, diff --git a/tests/FileManipulation/ReturnTypeManipulationTest.php b/tests/FileManipulation/ReturnTypeManipulationTest.php index 45c3b119a6a..addbaeaa45c 100644 --- a/tests/FileManipulation/ReturnTypeManipulationTest.php +++ b/tests/FileManipulation/ReturnTypeManipulationTest.php @@ -173,7 +173,7 @@ function foo() { /** * @return string[] * - * @psalm-return array{0:string} + * @psalm-return array{0: string} */ function foo() { return ["hello"]; @@ -191,7 +191,7 @@ function foo() { /** * @return string[] * - * @psalm-return array{0:string} + * @psalm-return array{0: string} */ function foo(): array { return ["hello"]; @@ -209,7 +209,7 @@ function foo() { /** * @return string[] * - * @psalm-return array{a:string, b?:string} + * @psalm-return array{a: string, b?: string} */ function foo(): array { return rand(0, 1) ? ["a" => "hello"] : ["a" => "goodbye", "b" => "hello again"]; @@ -234,7 +234,7 @@ function foo() { /** * @return int[] * - * @psalm-return array{a?:int, b?:int} + * @psalm-return array{a?: int, b?: int} */ function foo(): array { if (rand(0, 1)) { @@ -250,6 +250,48 @@ function foo(): array { ['MissingReturnType'], true, ], + 'addMissingObjectLikeReturnTypeWithNestedArrays' => [ + ' 1, + "b" => 2, + "c" => [ + "a" => 1, + "b" => 2, + "c" => [ + "a" => 1, + "b" => 2, + "c" => 3, + ], + ], + ]; + }', + ' 1, + "b" => 2, + "c" => [ + "a" => 1, + "b" => 2, + "c" => [ + "a" => 1, + "b" => 2, + "c" => 3, + ], + ], + ]; + }', + '7.0', + ['MissingReturnType'], + true, + ], 'addMissingObjectLikeReturnTypeSeparateStatements70' => [ '