mirror of
https://github.com/danog/psalm.git
synced 2025-01-18 19:42:21 +01:00
Display function signature on multiple lines when it has parameters (#1833)
This commit is contained in:
parent
aa6677a177
commit
caca3e52c9
@ -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;
|
||||
|
@ -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('<?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()'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user