Skip to content

Commit 4945098

Browse files
staabmondrejmirtes
authored andcommitted
cover ExtendedMethodReflection by bc-promise
1 parent 312fcf2 commit 4945098

9 files changed

+58
-23
lines changed

src/Reflection/Assertions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use function array_merge;
1111
use function count;
1212

13+
/**
14+
* @api
15+
*/
1316
class Assertions
1417
{
1518

src/Reflection/ExtendedMethodReflection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* and its methods in their code.
1515
*
1616
* Methods on ExtendedMethodReflection are subject to change.
17+
*
18+
* @api
1719
*/
1820
interface ExtendedMethodReflection extends MethodReflection
1921
{

src/Rules/Api/ApiClassImplementsRule.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
use PhpParser\Node;
66
use PhpParser\Node\Stmt\Class_;
77
use PHPStan\Analyser\Scope;
8-
use PHPStan\Reflection\FunctionReflection;
98
use PHPStan\Reflection\ReflectionProvider;
109
use PHPStan\Rules\Rule;
1110
use PHPStan\Rules\RuleError;
1211
use PHPStan\Rules\RuleErrorBuilder;
13-
use PHPStan\Type\Type;
1412
use function array_merge;
1513
use function count;
1614
use function in_array;
@@ -67,12 +65,7 @@ private function checkName(Scope $scope, Node\Name $name): array
6765
'https://github.com/phpstan/phpstan/discussions',
6866
))->build();
6967

70-
if (in_array($implementedClassReflection->getName(), [
71-
Type::class,
72-
ReflectionProvider::class,
73-
Scope::class,
74-
FunctionReflection::class,
75-
], true)) {
68+
if (in_array($implementedClassReflection->getName(), BcUncoveredInterface::CLASSES, true)) {
7669
return [$ruleError];
7770
}
7871

src/Rules/Api/ApiInterfaceExtendsRule.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Rules\Rule;
1010
use PHPStan\Rules\RuleError;
1111
use PHPStan\Rules\RuleErrorBuilder;
12-
use PHPStan\Type\Type;
1312
use function array_merge;
1413
use function count;
1514
use function in_array;
@@ -66,10 +65,7 @@ private function checkName(Scope $scope, Node\Name $name): array
6665
'https://github.com/phpstan/phpstan/discussions',
6766
))->build();
6867

69-
if (in_array($extendedInterfaceReflection->getName(), [
70-
Type::class,
71-
ReflectionProvider::class,
72-
], true)) {
68+
if (in_array($extendedInterfaceReflection->getName(), BcUncoveredInterface::CLASSES, true)) {
7369
return [$ruleError];
7470
}
7571

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Api;
4+
5+
use PHPStan\Analyser\Scope;
6+
use PHPStan\Reflection\ExtendedMethodReflection;
7+
use PHPStan\Reflection\FunctionReflection;
8+
use PHPStan\Reflection\ReflectionProvider;
9+
use PHPStan\Type\Type;
10+
11+
final class BcUncoveredInterface
12+
{
13+
14+
public const CLASSES = [
15+
Type::class,
16+
ReflectionProvider::class,
17+
Scope::class,
18+
FunctionReflection::class,
19+
ExtendedMethodReflection::class,
20+
];
21+
22+
}

tests/PHPStan/Rules/Api/ApiClassImplementsRuleTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,32 @@ 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-
18,
35+
19,
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-
52,
40+
53,
4141
$tip,
4242
],
4343
[
4444
'Implementing PHPStan\Reflection\ReflectionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
45-
327,
45+
328,
4646
$tip,
4747
],
4848
[
4949
'Implementing PHPStan\Analyser\Scope is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
50-
332,
50+
333,
5151
$tip,
5252
],
5353
[
5454
'Implementing PHPStan\Reflection\FunctionReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
55-
337,
55+
338,
56+
$tip,
57+
],
58+
[
59+
'Implementing PHPStan\Reflection\ExtendedMethodReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
60+
342,
5661
$tip,
5762
],
5863
]);

tests/PHPStan/Rules/Api/ApiInterfaceExtendsRuleTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@ 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-
9,
35+
10,
3636
$tip,
3737
],
3838
[
3939
'Extending PHPStan\Type\Type is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
40-
19,
40+
20,
4141
$tip,
4242
],
4343
[
4444
'Extending PHPStan\Reflection\ReflectionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
45-
24,
45+
25,
46+
$tip,
47+
],
48+
[
49+
'Extending PHPStan\Reflection\ExtendedMethodReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
50+
30,
4651
$tip,
4752
],
4853
]);

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
88
use PHPStan\Reflection\ClassMemberAccessAnswerer;
9+
use PHPStan\Reflection\ExtendedMethodReflection;
910
use PHPStan\Reflection\FunctionReflection;
1011
use PHPStan\Reflection\ReflectionProvider;
1112
use PHPStan\Type\DynamicFunctionThrowTypeExtension;
@@ -335,6 +336,8 @@ abstract class MyScope implements Scope
335336
}
336337

337338
abstract class MyFunctionReflection implements FunctionReflection
338-
{
339+
{}
339340

340-
}
341+
342+
abstract class MyMethodReflection implements ExtendedMethodReflection
343+
{}

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

Lines changed: 6 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\ExtendedMethodReflection;
67
use PHPStan\Reflection\ReflectionProvider;
78
use PHPStan\Type\DynamicFunctionThrowTypeExtension;
89

@@ -25,3 +26,8 @@ interface Dolor extends ReflectionProvider
2526
{
2627

2728
}
29+
30+
interface Ipsum extends ExtendedMethodReflection
31+
{
32+
33+
}

0 commit comments

Comments
 (0)