Skip to content

Commit e60d6d6

Browse files
committed
ReflectionProvider cannot be extended/implemented by 3rd party code
1 parent 4a8ccc6 commit e60d6d6

6 files changed

+45
-5
lines changed

src/Rules/Api/ApiClassImplementsRule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Type\Type;
1313
use function array_merge;
1414
use function count;
15+
use function in_array;
1516
use function sprintf;
1617

1718
/**
@@ -65,7 +66,10 @@ private function checkName(Scope $scope, Node\Name $name): array
6566
'https://github.com/phpstan/phpstan/discussions',
6667
))->build();
6768

68-
if ($implementedClassReflection->getName() === Type::class) {
69+
if (in_array($implementedClassReflection->getName(), [
70+
Type::class,
71+
ReflectionProvider::class,
72+
], true)) {
6973
return [$ruleError];
7074
}
7175

src/Rules/Api/ApiInterfaceExtendsRule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Type\Type;
1313
use function array_merge;
1414
use function count;
15+
use function in_array;
1516
use function sprintf;
1617

1718
/**
@@ -65,7 +66,10 @@ private function checkName(Scope $scope, Node\Name $name): array
6566
'https://github.com/phpstan/phpstan/discussions',
6667
))->build();
6768

68-
if ($extendedInterfaceReflection->getName() === Type::class) {
69+
if (in_array($extendedInterfaceReflection->getName(), [
70+
Type::class,
71+
ReflectionProvider::class,
72+
], true)) {
6973
return [$ruleError];
7074
}
7175

tests/PHPStan/Rules/Api/ApiClassImplementsRuleTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ public function testRuleOutOfPhpStan(): void
3232
$this->analyse([__DIR__ . '/data/class-implements-out-of-phpstan.php'], [
3333
[
3434
'Implementing PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
35-
17,
35+
18,
3636
$tip,
3737
],
3838
[
3939
'Implementing PHPStan\Type\Type is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
40-
51,
40+
52,
41+
$tip,
42+
],
43+
[
44+
'Implementing PHPStan\Reflection\ReflectionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
45+
312,
4146
$tip,
4247
],
4348
]);

tests/PHPStan/Rules/Api/ApiInterfaceExtendsRuleTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,17 @@ public function testRuleOutOfPhpStan(): void
3232
$this->analyse([__DIR__ . '/data/interface-extends-out-of-phpstan.php'], [
3333
[
3434
'Extending PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
35-
8,
35+
9,
36+
$tip,
37+
],
38+
[
39+
'Extending PHPStan\Type\Type is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
40+
19,
41+
$tip,
42+
],
43+
[
44+
'Extending PHPStan\Reflection\ReflectionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
45+
24,
3646
$tip,
3747
],
3848
]);

tests/PHPStan/Rules/Api/data/class-implements-out-of-phpstan.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
88
use PHPStan\Reflection\ClassMemberAccessAnswerer;
99
use PHPStan\Reflection\FunctionReflection;
10+
use PHPStan\Reflection\ReflectionProvider;
1011
use PHPStan\Type\DynamicFunctionThrowTypeExtension;
1112
use PHPStan\Type\GeneralizePrecision;
1213
use PHPStan\Type\Generic\TemplateTypeReference;
@@ -307,3 +308,8 @@ public static function __set_state(array $properties): \PHPStan\Type\Type
307308

308309

309310
}
311+
312+
abstract class Dolor implements ReflectionProvider
313+
{
314+
315+
}

tests/PHPStan/Rules/Api/data/interface-extends-out-of-phpstan.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\InterfaceExtends;
44

55
use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
6+
use PHPStan\Reflection\ReflectionProvider;
67
use PHPStan\Type\DynamicFunctionThrowTypeExtension;
78

89
interface Foo extends DynamicThrowTypeExtensionProvider
@@ -14,3 +15,13 @@ interface Bar extends DynamicFunctionThrowTypeExtension
1415
{
1516

1617
}
18+
19+
interface Lorem extends \PHPStan\Type\Type
20+
{
21+
22+
}
23+
24+
interface Dolor extends ReflectionProvider
25+
{
26+
27+
}

0 commit comments

Comments
 (0)