From caca3e52c91f521948881e7da8e8527157d116cd Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Sat, 22 Jun 2019 19:07:56 +0200 Subject: [PATCH] Display function signature on multiple lines when it has parameters (#1833) --- src/Psalm/Storage/FunctionLikeStorage.php | 8 ++++---- tests/LanguageServer/SymbolLookupTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Storage/FunctionLikeStorage.php b/src/Psalm/Storage/FunctionLikeStorage.php index dd8448e3c..5aca88714 100644 --- a/src/Psalm/Storage/FunctionLikeStorage.php +++ b/src/Psalm/Storage/FunctionLikeStorage.php @@ -171,15 +171,15 @@ class FunctionLikeStorage public function __toString() { - $symbol_text = 'function ' . $this->cased_name . '(' . implode( - ', ', + $symbol_text = 'function ' . $this->cased_name . '(' . (!empty($this->params) ? PHP_EOL : '') . implode( + ',' . PHP_EOL, array_map( function (FunctionLikeParameter $param) : string { - return ($param->type ?: 'mixed') . ' $' . $param->name; + return ' ' . ($param->type ?: 'mixed') . ' $' . $param->name; }, $this->params ) - ) . ') : ' . ($this->return_type ?: 'mixed'); + ) . (!empty($this->params) ? PHP_EOL : '') . ') : ' . ($this->return_type ?: 'mixed'); if (!$this instanceof MethodStorage) { return $symbol_text; diff --git a/tests/LanguageServer/SymbolLookupTest.php b/tests/LanguageServer/SymbolLookupTest.php index 5b6c3e6c4..57f247e1f 100644 --- a/tests/LanguageServer/SymbolLookupTest.php +++ b/tests/LanguageServer/SymbolLookupTest.php @@ -65,6 +65,14 @@ class SymbolLookupTest extends \Psalm\Tests\TestCase function bar() : int { return 5; + } + + function baz(int $a) : int { + return $a; + } + + function qux(int $a, int $b) : int { + return $a + $b; }' ); @@ -78,6 +86,8 @@ class SymbolLookupTest extends \Psalm\Tests\TestCase $this->assertSame('getSymbolInformation('somefile.php', 'B\A::$a')); $this->assertSame('getSymbolInformation('somefile.php', 'B\bar()')); $this->assertSame('getSymbolInformation('somefile.php', 'B\A::BANANA')); + $this->assertSame("getSymbolInformation('somefile.php', 'B\baz()')); + $this->assertSame("getSymbolInformation('somefile.php', 'B\qux()')); } /**