1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

offset the starting position of the function in case of attributes

This commit is contained in:
orklah 2021-09-29 21:19:04 +02:00
parent afbda6d0f6
commit 5a99c9be94
2 changed files with 34 additions and 0 deletions

View File

@ -123,6 +123,14 @@ class FunctionDocblockManipulator
$this->docblock_end = $function_start = (int)$stmt->getAttribute('startFilePos');
$function_end = (int)$stmt->getAttribute('endFilePos');
$attributes = $stmt->getAttrGroups();
foreach ($attributes as $attribute) {
// if we have attribute groups, we need to consider that the function starts after them
if ((int) $attribute->getAttribute('endFilePos') > $function_start) {
$function_start = (int) $attribute->getAttribute('endFilePos');
}
}
foreach ($stmt->params as $param) {
if ($param->var instanceof PhpParser\Node\Expr\Variable
&& \is_string($param->var->name)

View File

@ -1088,6 +1088,32 @@ class MissingReturnTypeTest extends FileManipulationTestCase
false,
true,
],
'WithAttributes' => [
'<?php
class A
{
#[Foo()]
public function bar()
{
}
}
',
'<?php
class A
{
#[Foo()]
public function bar(): void
{
}
}
',
'7.1',
['MissingReturnType'],
true,
true,
],
];
}
}