Skip to content
Permalink
Browse files

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
  • Loading branch information...
Kocal authored and muglug committed Jun 16, 2019
1 parent 7fc11af commit 37d719ed67feff858777a74b5b8474eb51e9697e
Showing with 53 additions and 11 deletions.
  1. +3 −3 src/Psalm/Type/Atomic/ObjectLike.php
  2. +50 −8 tests/FileManipulation/ReturnTypeManipulationTest.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,
@@ -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' => [
'<?php
function foo() {
return [
"a" => 1,
"b" => 2,
"c" => [
"a" => 1,
"b" => 2,
"c" => [
"a" => 1,
"b" => 2,
"c" => 3,
],
],
];
}',
'<?php
/**
* @return ((int[]|int)[]|int)[]
*
* @psalm-return array{a: int, b: int, c: array{a: int, b: int, c: array{a: int, b: int, c: int}}}
*/
function foo(): array {
return [
"a" => 1,
"b" => 2,
"c" => [
"a" => 1,
"b" => 2,
"c" => [
"a" => 1,
"b" => 2,
"c" => 3,
],
],
];
}',
'7.0',
['MissingReturnType'],
true,
],
'addMissingObjectLikeReturnTypeSeparateStatements70' => [
'<?php
function foo() {
@@ -267,7 +309,7 @@ function foo() {
/**
* @return string[]
*
* @psalm-return array{a:string, b?:string}
* @psalm-return array{a: string, b?: string}
*/
function foo(): array {
if (rand(0, 1)) {
@@ -890,7 +932,7 @@ class D {
/**
* @return B\C[]
*
* @psalm-return array{0:B\C}
* @psalm-return array{0: B\C}
*/
public function getArrayOfC(): array {
return [new \A\B\C];
@@ -1241,7 +1283,7 @@ class A {
/**
* @return string[]
*
* @psalm-return array{0:string}
* @psalm-return array{0: string}
*/
public function foo(): ?array {
return ["hello"];
@@ -1267,7 +1309,7 @@ class A {
/**
* @return string[]
*
* @psalm-return array{0:string}
* @psalm-return array{0: string}
*/
public function foo(): array {
return ["hello"];

0 comments on commit 37d719e

Please sign in to comment.
You can’t perform that action at this time.