Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Reflection/Assertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use function array_merge;
use function count;

/**
* @api
*/
class Assertions
{

Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/ExtendedMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* and its methods in their code.
*
* Methods on ExtendedMethodReflection are subject to change.
*
* @api
Copy link
Contributor Author

Choose a reason for hiding this comment

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

above this interface is this big comment, mentioning that this interface is not meant for re-use. I guess it should be dropped now?

Copy link
Member

Choose a reason for hiding this comment

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

I'll rewrite it after merge.

*/
interface ExtendedMethodReflection extends MethodReflection
{
Expand Down
9 changes: 1 addition & 8 deletions src/Rules/Api/ApiClassImplementsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\Type;
use function array_merge;
use function count;
use function in_array;
Expand Down Expand Up @@ -67,12 +65,7 @@ private function checkName(Scope $scope, Node\Name $name): array
'https://github.com/phpstan/phpstan/discussions',
))->build();

if (in_array($implementedClassReflection->getName(), [
Type::class,
ReflectionProvider::class,
Scope::class,
FunctionReflection::class,
], true)) {
if (in_array($implementedClassReflection->getName(), BcUncoveredInterface::CLASSES, true)) {
return [$ruleError];
}

Expand Down
6 changes: 1 addition & 5 deletions src/Rules/Api/ApiInterfaceExtendsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\Type;
use function array_merge;
use function count;
use function in_array;
Expand Down Expand Up @@ -66,10 +65,7 @@ private function checkName(Scope $scope, Node\Name $name): array
'https://github.com/phpstan/phpstan/discussions',
))->build();

if (in_array($extendedInterfaceReflection->getName(), [
Type::class,
ReflectionProvider::class,
], true)) {
if (in_array($extendedInterfaceReflection->getName(), BcUncoveredInterface::CLASSES, true)) {
Copy link
Contributor Author

@staabm staabm Oct 25, 2022

Choose a reason for hiding this comment

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

I am re-using the same constant as in ApiClassImplementsRule.. thats how I understand the todo.

since we are now ignoring 5 classes here instead of only 2, I could add more tests.
but I wasn't sure whether I should DRY only Type::class, ReflectionProvider::class or all 5 class-strings..?

return [$ruleError];
}

Expand Down
22 changes: 22 additions & 0 deletions src/Rules/Api/BcUncoveredInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace PHPStan\Rules\Api;

use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Type;

final class BcUncoveredInterface
Copy link
Member

@ondrejmirtes ondrejmirtes Oct 26, 2022

Choose a reason for hiding this comment

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

A food for thought - in the future we could add a new annotation like @api-interface-forbid-implements. That would allow us not to maintain these lists and also BackwardCompatibilityCheck with each new interface.

{

public const CLASSES = [
Type::class,
ReflectionProvider::class,
Scope::class,
FunctionReflection::class,
ExtendedMethodReflection::class,
];

}
15 changes: 10 additions & 5 deletions tests/PHPStan/Rules/Api/ApiClassImplementsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,32 @@ public function testRuleOutOfPhpStan(): void
$this->analyse([__DIR__ . '/data/class-implements-out-of-phpstan.php'], [
[
'Implementing PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
18,
19,
$tip,
],
[
'Implementing PHPStan\Type\Type is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
52,
53,
$tip,
],
[
'Implementing PHPStan\Reflection\ReflectionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
327,
328,
$tip,
],
[
'Implementing PHPStan\Analyser\Scope is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
332,
333,
$tip,
],
[
'Implementing PHPStan\Reflection\FunctionReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
337,
338,
$tip,
],
[
'Implementing PHPStan\Reflection\ExtendedMethodReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
342,
$tip,
],
]);
Expand Down
11 changes: 8 additions & 3 deletions tests/PHPStan/Rules/Api/ApiInterfaceExtendsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,22 @@ public function testRuleOutOfPhpStan(): void
$this->analyse([__DIR__ . '/data/interface-extends-out-of-phpstan.php'], [
[
'Extending PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
9,
10,
$tip,
],
[
'Extending PHPStan\Type\Type is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
19,
20,
$tip,
],
[
'Extending PHPStan\Reflection\ReflectionProvider is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
24,
25,
$tip,
],
[
'Extending PHPStan\Reflection\ExtendedMethodReflection is not covered by backward compatibility promise. The interface might change in a minor PHPStan version.',
30,
$tip,
],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
use PHPStan\Reflection\ClassMemberAccessAnswerer;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\DynamicFunctionThrowTypeExtension;
Expand Down Expand Up @@ -335,6 +336,8 @@ abstract class MyScope implements Scope
}

abstract class MyFunctionReflection implements FunctionReflection
{
{}

}

abstract class MyMethodReflection implements ExtendedMethodReflection
{}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\InterfaceExtends;

use PHPStan\DependencyInjection\Type\DynamicThrowTypeExtensionProvider;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\DynamicFunctionThrowTypeExtension;

Expand All @@ -25,3 +26,8 @@ interface Dolor extends ReflectionProvider
{

}

interface Ipsum extends ExtendedMethodReflection
{

}