Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix @psalm-internal with trailing whitespaces #7207

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Analyzer/CommentAnalyzer.php
Expand Up @@ -237,13 +237,13 @@ private static function decorateVarDocblockComment(
}

if (isset($parsed_docblock->tags['psalm-internal'])) {
$psalm_internal = reset($parsed_docblock->tags['psalm-internal']);
$psalm_internal = trim(reset($parsed_docblock->tags['psalm-internal']));

if (!$psalm_internal) {
throw new DocblockParseException('psalm-internal annotation used without specifying namespace');
}

$var_comment->psalm_internal = reset($parsed_docblock->tags['psalm-internal']);
$var_comment->psalm_internal = $psalm_internal;
$var_comment->internal = true;
}

Expand Down
Expand Up @@ -213,13 +213,13 @@ public static function parse(
}

if (isset($parsed_docblock->tags['psalm-internal'])) {
$psalm_internal = reset($parsed_docblock->tags['psalm-internal']);
if ($psalm_internal) {
$info->psalm_internal = $psalm_internal;
} else {
$psalm_internal = trim(reset($parsed_docblock->tags['psalm-internal']));

if (!$psalm_internal) {
throw new DocblockParseException('psalm-internal annotation used without specifying namespace');
}

$info->psalm_internal = $psalm_internal;
$info->internal = true;
}

Expand Down
Expand Up @@ -359,13 +359,13 @@ public static function parse(PhpParser\Comment\Doc $comment): FunctionDocblockCo
}

if (isset($parsed_docblock->tags['psalm-internal'])) {
$psalm_internal = reset($parsed_docblock->tags['psalm-internal']);
if ($psalm_internal) {
$info->psalm_internal = $psalm_internal;
} else {
$psalm_internal = trim(reset($parsed_docblock->tags['psalm-internal']));

if (!$psalm_internal) {
throw new DocblockParseException('@psalm-internal annotation used without specifying namespace');
}
$info->psalm_internal = reset($parsed_docblock->tags['psalm-internal']);

$info->psalm_internal = $psalm_internal;
$info->internal = true;
}

Expand Down
32 changes: 32 additions & 0 deletions tests/InternalAnnotationTest.php
Expand Up @@ -301,6 +301,17 @@ public function batBat() : void {
}
}',
],
'psalmInternalMethodWithTrailingWhitespace' => [
'<?php
namespace A\B {
class Foo {
/** @psalm-internal A\B */
public static function barBar(): void {
self::barBar();
}
}
}',
],
'internalToClassMethodWithCallSameNamespace' => [
'<?php
namespace A\B {
Expand Down Expand Up @@ -459,6 +470,14 @@ class Foo { }
class Bar extends \A\B\Foo {}
}',
],
'psalmInternalClassWithTrailingWhitespace' => [
'<?php
namespace A\B {
/** @psalm-internal A\B */
class Foo {}
class Bar extends Foo {}
}',
],
'psalmInternalPropertyGet' => [
'<?php
namespace A\B {
Expand Down Expand Up @@ -499,6 +518,19 @@ public function batBat() : void {
}
}',
],
'psalmInternalPropertyWithTrailingWhitespace' => [
'<?php
namespace A\B {
class Foo {
/** @psalm-internal A\B */
public int $foo = 0;

public function barBar() : void {
$this->foo = 42;
}
}
}',
],
'psalmInternalMethodInTraitWithCall' => [
'<?php
namespace A {
Expand Down