mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
psalm-internal: Prevent use of @psalm-internal without @internal
This commit is contained in:
parent
6fbe2b0837
commit
f4c754737f
@ -246,9 +246,12 @@ unrelated to the namespace of the calling code, i.e. not sharing the first eleme
|
||||
In contrast for `@psalm-internal`, the docbloc line must specify a namespace. An issue is raised of the calling code
|
||||
is not within the given namespace.
|
||||
|
||||
As other tools do not support `@psalm-internal`, it may only be used in conjuction with `@internal`.
|
||||
|
||||
```PHP
|
||||
namespace A\B {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
class Foo { }
|
||||
|
@ -133,6 +133,10 @@ class CommentAnalyzer
|
||||
throw new DocblockParseException('psalm-internal annotation used without specifying namespace');
|
||||
}
|
||||
$var_comment->psalm_internal = reset($comments['specials']['psalm-internal']);
|
||||
|
||||
if (!$var_comment->internal) {
|
||||
throw new DocblockParseException('@psalm-internal annotation used without @internal');
|
||||
}
|
||||
}
|
||||
|
||||
$var_comments[] = $var_comment;
|
||||
@ -386,11 +390,17 @@ class CommentAnalyzer
|
||||
if ($psalm_internal) {
|
||||
$info->psalm_internal = $psalm_internal;
|
||||
} else {
|
||||
throw new DocblockParseException('psalm-internal annotation used without specifying namespace');
|
||||
throw new DocblockParseException('@psalm-internal annotation used without specifying namespace');
|
||||
}
|
||||
$info->psalm_internal = reset($comments['specials']['psalm-internal']);
|
||||
|
||||
if (! $info->internal) {
|
||||
throw new DocblockParseException('@psalm-internal annotation used without @internal');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isset($comments['specials']['psalm-suppress'])) {
|
||||
foreach ($comments['specials']['psalm-suppress'] as $suppress_entry) {
|
||||
$info->suppress[] = preg_split('/[\s]+/', $suppress_entry)[0];
|
||||
@ -690,6 +700,10 @@ class CommentAnalyzer
|
||||
} else {
|
||||
throw new DocblockParseException('psalm-internal annotation used without specifying namespace');
|
||||
}
|
||||
|
||||
if (! $info->internal) {
|
||||
throw new DocblockParseException('@psalm-internal annotation used without @internal');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($comments['specials']['psalm-seal-properties'])) {
|
||||
|
@ -18,6 +18,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
public static function barBar(): void {
|
||||
@ -38,6 +39,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
public static function barBar(): void {
|
||||
@ -58,6 +60,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B\Foo
|
||||
*/
|
||||
public static function barBar(): void {
|
||||
@ -73,6 +76,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'<?php
|
||||
namespace A\B {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A
|
||||
*/
|
||||
class Foo {
|
||||
@ -93,6 +97,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'<?php
|
||||
namespace A {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A
|
||||
*/
|
||||
class Foo extends \B\Foo {
|
||||
@ -119,6 +124,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'<?php
|
||||
namespace A\B {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
class Foo { }
|
||||
@ -136,6 +142,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'<?php
|
||||
namespace A\B {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
class Foo { }
|
||||
@ -150,6 +157,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
* @var ?int
|
||||
*/
|
||||
@ -170,6 +178,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
* @var ?int
|
||||
*/
|
||||
@ -189,6 +198,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'<?php
|
||||
namespace A {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A
|
||||
*/
|
||||
trait T {
|
||||
@ -224,6 +234,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
public static function barBar(): void {
|
||||
@ -245,6 +256,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B\Foo
|
||||
*/
|
||||
public static function barBar(): void {
|
||||
@ -265,6 +277,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'<?php
|
||||
namespace A\B {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
class Foo {
|
||||
@ -286,6 +299,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'<?php
|
||||
namespace A\B {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
class Foo { }
|
||||
@ -304,6 +318,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'<?php
|
||||
namespace A\B {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
class Foo { }
|
||||
@ -319,6 +334,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
* @var ?int
|
||||
*/
|
||||
@ -340,6 +356,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal A\B
|
||||
* @var ?int
|
||||
*/
|
||||
@ -359,7 +376,10 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'internalClassMissingNamespace' => [
|
||||
'<?php
|
||||
|
||||
/** @psalm-internal */
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal
|
||||
*/
|
||||
class Foo {}
|
||||
|
||||
',
|
||||
@ -370,6 +390,7 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
class Foo {
|
||||
/**
|
||||
* @var int
|
||||
* @internal
|
||||
* @psalm-internal
|
||||
*/
|
||||
var $bar;
|
||||
@ -380,13 +401,56 @@ class PsalmInternalAnnotationTest extends TestCase
|
||||
'internalMethodMissingNamespace' => [
|
||||
'<?php
|
||||
class Foo {
|
||||
/** @psalm-internal */
|
||||
/**
|
||||
* @internal
|
||||
* @psalm-internal
|
||||
*/
|
||||
function Bar(): void {}
|
||||
}
|
||||
|
||||
',
|
||||
'error_message' => 'psalm-internal annotation used without specifying namespace',
|
||||
],
|
||||
'internalClassMissingInternalAnnotation' => [
|
||||
'<?php
|
||||
namespace A\B {
|
||||
/**
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
class Foo { }
|
||||
}
|
||||
',
|
||||
'error_message' => 'psalm-internal annotation used without @internal',
|
||||
],
|
||||
'internalPropertyMissingInternalAnnotation' => [
|
||||
'<?php
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @var int
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
public $foo;
|
||||
}
|
||||
}
|
||||
',
|
||||
'error_message' => 'psalm-internal annotation used without @internal',
|
||||
],
|
||||
'internalFunctionMissingInternalAnnotation' => [
|
||||
'<?php
|
||||
namespace A\B {
|
||||
class Foo {
|
||||
/**
|
||||
* @psalm-internal A\B
|
||||
*/
|
||||
public function foo()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
',
|
||||
'error_message' => 'psalm-internal annotation used without @internal',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user