Skip to content

Commit

Permalink
document that @psalm-internal works for namespace + class too
Browse files Browse the repository at this point in the history
as used in #9584
  • Loading branch information
kkmuffme committed Mar 27, 2024
1 parent 4b01704 commit f8724a2
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/annotating_code/supported_annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ $b = $a->bar(); // this call fails

### `@psalm-internal`

Used to mark a class, property or function as internal to a given namespace. Psalm treats this slightly differently to
the PHPDoc `@internal` tag. For `@internal`, an issue is raised if the calling code is in a namespace completely
unrelated to the namespace of the calling code, i.e. not sharing the first element of the namespace.
Used to mark a class, property or function as internal to a given namespace or class. Psalm treats this slightly
differently to the PHPDoc `@internal` tag. For `@internal`, an issue is raised if the calling code is in a namespace
completely unrelated to the namespace of the calling code, i.e. not sharing the first element of the namespace.

In contrast for `@psalm-internal`, the docblock line must specify a namespace. An issue is raised if the calling code
is not within the given namespace.
Expand Down
82 changes: 82 additions & 0 deletions tests/InternalAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,46 @@ public function baz(): void
}
',
],
'psalmInternalClassWithCallClass' => [
'code' => '<?php
namespace A {
/**
* @psalm-internal B\Bat
*/
class Foo {
public static function barBar(): void {
}
}
}
namespace B {
class Bat {
public function batBat() : void {
\A\Foo::barBar();
}
}
}',
],
'psalmInternalMethodWithCallClass' => [
'code' => '<?php
namespace A {
class Foo {
/**
* @psalm-internal B\Bat
*/
public static function barBar(): void {
}
}
}
namespace B {
class Bat {
public function batBat() : void {
\A\Foo::barBar();
}
}
}',
],
'callToInternalMethodFromAnonymousClass' => [
'code' => <<<'PHP'
<?php
Expand Down Expand Up @@ -1118,6 +1158,48 @@ public function __construct() {}
',
'error_message' => 'InternalMethod',
],
'psalmInternalClassWithCallClass' => [
'code' => '<?php
namespace A {
/**
* @psalm-internal B\Bar
*/
class Foo {
public static function barBar(): void {
}
}
}
namespace B {
class Bat {
public function batBat() : void {
\A\Foo::barBar();
}
}
}',
'error_message' => 'InternalMethod',
],
'psalmInternalMethodWithCallClass' => [
'code' => '<?php
namespace A {
class Foo {
/**
* @psalm-internal B\Bar
*/
public static function barBar(): void {
}
}
}
namespace B {
class Bat {
public function batBat() : void {
\A\Foo::barBar();
}
}
}',
'error_message' => 'InternalMethod',
],
];
}
}

0 comments on commit f8724a2

Please sign in to comment.