Skip to content

Commit

Permalink
Display function signature on multiple lines when it has parameters (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
iluuu1994 authored and muglug committed Jun 22, 2019
1 parent aa6677a commit caca3e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Psalm/Storage/FunctionLikeStorage.php
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/LanguageServer/SymbolLookupTest.php
Expand Up @@ -65,6 +65,14 @@ public function foo() : void {
function bar() : int {
return 5;
}
function baz(int $a) : int {
return $a;
}
function qux(int $a, int $b) : int {
return $a + $b;
}'
);

Expand All @@ -78,6 +86,8 @@ function bar() : int {
$this->assertSame('<?php protected int|null $a', $codebase->getSymbolInformation('somefile.php', 'B\A::$a'));
$this->assertSame('<?php function B\bar() : int', $codebase->getSymbolInformation('somefile.php', 'B\bar()'));
$this->assertSame('<?php BANANA', $codebase->getSymbolInformation('somefile.php', 'B\A::BANANA'));
$this->assertSame("<?php function B\baz(\n int \$a\n) : int", $codebase->getSymbolInformation('somefile.php', 'B\baz()'));
$this->assertSame("<?php function B\qux(\n int \$a,\n int \$b\n) : int", $codebase->getSymbolInformation('somefile.php', 'B\qux()'));
}

/**
Expand Down

0 comments on commit caca3e5

Please sign in to comment.