Skip to content

Commit

Permalink
psalm-internal no longer requires internal annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jul 26, 2020
1 parent e398535 commit 42ad366
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 74 deletions.
14 changes: 3 additions & 11 deletions src/Psalm/Internal/Analyzer/CommentAnalyzer.php
Expand Up @@ -237,10 +237,7 @@ private static function decorateVarDocblockComment(
}

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

if (!$var_comment->internal) {
throw new DocblockParseException('@psalm-internal annotation used without @internal');
}
$var_comment->internal = true;
}
}

Expand Down Expand Up @@ -627,10 +624,7 @@ public static function extractFunctionDocblockInfo(PhpParser\Comment\Doc $commen
throw new DocblockParseException('@psalm-internal annotation used without specifying namespace');
}
$info->psalm_internal = reset($parsed_docblock->tags['psalm-internal']);

if (! $info->internal) {
throw new DocblockParseException('@psalm-internal annotation used without @internal');
}
$info->internal = true;
}

if (isset($parsed_docblock->tags['psalm-suppress'])) {
Expand Down Expand Up @@ -926,9 +920,7 @@ public static function extractClassLikeDocblockInfo(
throw new DocblockParseException('psalm-internal annotation used without specifying namespace');
}

if (! $info->internal) {
throw new DocblockParseException('@psalm-internal annotation used without @internal');
}
$info->internal = true;
}

if (isset($parsed_docblock->tags['mixin'])) {
Expand Down
63 changes: 0 additions & 63 deletions tests/InternalAnnotationTest.php
Expand Up @@ -262,7 +262,6 @@ public function batBat() : void {
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B
*/
public static function barBar(): void {
Expand All @@ -283,7 +282,6 @@ public function batBat() : void {
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B
*/
public static function barBar(): void {
Expand All @@ -304,7 +302,6 @@ public function batBat() : void {
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B
*/
public static function barBar(): void {
Expand All @@ -320,7 +317,6 @@ public static function foo(): void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A
*/
class Foo {
Expand All @@ -341,7 +337,6 @@ public function batBat() : void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo {
Expand All @@ -366,7 +361,6 @@ public function batBat(\A\B\Foo $instance): void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo {
Expand All @@ -390,7 +384,6 @@ public function batBat(\A\B\Foo $instance): void {
'<?php
namespace A {
/**
* @internal
* @psalm-internal A
*/
class Foo extends \B\Foo {
Expand All @@ -417,7 +410,6 @@ public static function barBar(): void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo { }
Expand All @@ -437,7 +429,6 @@ public function batBat() : void {
interface Bar {};
/**
* @internal
* @psalm-internal A\B
*/
class Foo { }
Expand All @@ -455,7 +446,6 @@ public function batBat(\A\B\Bar $bar) : void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo { }
Expand All @@ -470,7 +460,6 @@ class Bar extends \A\B\Foo {}
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B
* @var ?int
*/
Expand All @@ -491,7 +480,6 @@ public function batBat() : void {
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B
* @var ?int
*/
Expand All @@ -511,7 +499,6 @@ public function batBat() : void {
'<?php
namespace A {
/**
* @internal
* @psalm-internal A
*/
trait T {
Expand Down Expand Up @@ -752,7 +739,6 @@ public function batBat() : void {
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B
*/
public static function barBar(): void {
Expand All @@ -774,7 +760,6 @@ public function batBat(): void {
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B\Foo
*/
public static function barBar(): void {
Expand All @@ -795,7 +780,6 @@ public function batBat(): void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo {
Expand All @@ -817,7 +801,6 @@ public function batBat(): void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo {
Expand All @@ -842,7 +825,6 @@ public function batBat(): void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo {
Expand All @@ -868,7 +850,6 @@ public function batBat(): void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo { }
Expand All @@ -887,7 +868,6 @@ public function batBat(): void {
'<?php
namespace A\B {
/**
* @internal
* @psalm-internal A\B
*/
class Foo { }
Expand All @@ -903,7 +883,6 @@ class Bar extends \A\B\Foo {}
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B
* @var ?int
*/
Expand All @@ -925,7 +904,6 @@ public function batBat() : void {
namespace A\B {
class Foo {
/**
* @internal
* @psalm-internal A\B
* @var ?int
*/
Expand Down Expand Up @@ -971,7 +949,6 @@ class Foo {
'<?php
class Foo {
/**
* @internal
* @psalm-internal
*/
function Bar(): void {}
Expand All @@ -980,46 +957,6 @@ function Bar(): void {}
',
'error_message' => 'psalm-internal annotation used without specifying namespace',
],
'psalmInternalClassMissingInternalAnnotation' => [
'<?php
namespace A\B {
/**
* @psalm-internal A\B
*/
class Foo { }
}
',
'error_message' => 'psalm-internal annotation used without @internal',
],
'psalmInternalPropertyMissingInternalAnnotation' => [
'<?php
namespace A\B {
class Foo {
/**
* @var int
* @psalm-internal A\B
*/
public $foo;
}
}
',
'error_message' => 'psalm-internal annotation used without @internal',
],
'psalmInternalFunctionMissingInternalAnnotation' => [
'<?php
namespace A\B {
class Foo {
/**
* @psalm-internal A\B
*/
public function foo()
{
}
}
}
',
'error_message' => 'psalm-internal annotation used without @internal',
],
];
}
}

1 comment on commit 42ad366

@bdsl
Copy link
Contributor

@bdsl bdsl commented on 42ad366 Jul 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and thanks for the CC @muglug . I always wondered whether this rule was helpful, and if remember correctly your change may improve compatibility with some other tool(s) that interpret @internal differently. Although testing now in the PHPStan playground there's no issue reported even for newing up a class marked with @internal in an unrelated namespace.

The docs need updating for this: https://github.com/vimeo/psalm/blob/42ad366dc8ccaf349cda3f2ae45694f3f662828a/docs/annotating_code/supported_annotations.md#psalm-internal

Please sign in to comment.