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

add annotation @psalm-param-out (#4717)

* add annotation @psalm-param-out

* add tag in documentation
This commit is contained in:
orklah 2020-11-27 23:05:26 +01:00 committed by Daniil Gentili
parent 3be31563d6
commit b084e2c4bd
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 14 additions and 6 deletions

View File

@ -51,7 +51,7 @@ function bat(): string {
There are a number of custom tags that determine how Psalm treats your code. There are a number of custom tags that determine how Psalm treats your code.
### `@param-out` ### `@param-out`, `@psalm-param-out`
This is used to specify that a by-ref type is different from the one that entered. In the function below the first param can be null, but once the function has executed the by-ref value is not null. This is used to specify that a by-ref type is different from the one that entered. In the function below the first param can be null, but once the function has executed the by-ref value is not null.

View File

@ -35,8 +35,8 @@ class DocComment
'allow-private-mutation', 'readonly-allow-private-mutation', 'allow-private-mutation', 'readonly-allow-private-mutation',
'yield', 'trace', 'import-type', 'flow', 'taint-specialize', 'taint-escape', 'yield', 'trace', 'import-type', 'flow', 'taint-specialize', 'taint-escape',
'taint-unescape', 'self-out', 'consistent-constructor', 'stub-override', 'taint-unescape', 'self-out', 'consistent-constructor', 'stub-override',
'require-extends', 'require-implements', 'if-this-is',
'if-this-is' 'require-extends', 'require-implements', 'param-out'
]; ];
/** /**

View File

@ -91,8 +91,8 @@ class FunctionLikeDocblockParser
} }
} }
if (isset($parsed_docblock->tags['param-out'])) { if (isset($parsed_docblock->combined_tags['param-out'])) {
foreach ($parsed_docblock->tags['param-out'] as $offset => $param) { foreach ($parsed_docblock->combined_tags['param-out'] as $offset => $param) {
$line_parts = CommentAnalyzer::splitDocLine($param); $line_parts = CommentAnalyzer::splitDocLine($param);
if (count($line_parts) === 1 && isset($line_parts[0][0]) && $line_parts[0][0] === '$') { if (count($line_parts) === 1 && isset($line_parts[0][0]) && $line_parts[0][0] === '$') {

View File

@ -233,5 +233,13 @@ class DocblockParser
+ ($docblock->tags['phpstan-var'] ?? []) + ($docblock->tags['phpstan-var'] ?? [])
+ ($docblock->tags['psalm-var'] ?? []); + ($docblock->tags['psalm-var'] ?? []);
} }
if (isset($docblock->tags['param-out'])
|| isset($docblock->tags['psalm-param-out'])
) {
$docblock->combined_tags['param-out']
= ($docblock->tags['param-out'] ?? [])
+ ($docblock->tags['psalm-param-out'] ?? []);
}
} }
} }

View File

@ -2135,7 +2135,7 @@ class UnusedVariableTest extends TestCase
} }
/** /**
* @param-out int $c * @psalm-param-out int $c
*/ */
function takesByRef(?int &$c) : void { function takesByRef(?int &$c) : void {
$c = 7; $c = 7;