Skip to content

Commit

Permalink
Added missing rules to StubValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 4, 2024
1 parent d598545 commit bf19914
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
20 changes: 20 additions & 0 deletions src/PhpDoc/StubValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
use PHPStan\Rules\Generics\ClassAncestorsRule;
use PHPStan\Rules\Generics\ClassTemplateTypeRule;
use PHPStan\Rules\Generics\CrossCheckInterfacesHelper;
use PHPStan\Rules\Generics\EnumAncestorsRule;
use PHPStan\Rules\Generics\EnumTemplateTypeRule;
use PHPStan\Rules\Generics\FunctionSignatureVarianceRule;
use PHPStan\Rules\Generics\FunctionTemplateTypeRule;
use PHPStan\Rules\Generics\GenericAncestorsCheck;
Expand All @@ -58,8 +60,10 @@
use PHPStan\Rules\Generics\MethodTagTemplateTypeRule;
use PHPStan\Rules\Generics\MethodTagTemplateTypeTraitRule;
use PHPStan\Rules\Generics\MethodTemplateTypeRule;
use PHPStan\Rules\Generics\PropertyVarianceRule;
use PHPStan\Rules\Generics\TemplateTypeCheck;
use PHPStan\Rules\Generics\TraitTemplateTypeRule;
use PHPStan\Rules\Generics\UsedTraitsRule;
use PHPStan\Rules\Generics\VarianceCheck;
use PHPStan\Rules\Methods\ExistingClassesInTypehintsRule;
use PHPStan\Rules\Methods\MethodParameterComparisonHelper;
Expand All @@ -69,6 +73,10 @@
use PHPStan\Rules\Methods\MissingMethodSelfOutTypeRule;
use PHPStan\Rules\Methods\OverridingMethodRule;
use PHPStan\Rules\MissingTypehintCheck;
use PHPStan\Rules\PhpDoc\AssertRuleHelper;
use PHPStan\Rules\PhpDoc\ConditionalReturnTypeRuleHelper;
use PHPStan\Rules\PhpDoc\FunctionAssertRule;
use PHPStan\Rules\PhpDoc\FunctionConditionalReturnTypeRule;
use PHPStan\Rules\PhpDoc\GenericCallableRuleHelper;
use PHPStan\Rules\PhpDoc\IncompatibleClassConstantPhpDocTypeRule;
use PHPStan\Rules\PhpDoc\IncompatibleParamImmediatelyInvokedCallableRule;
Expand All @@ -78,6 +86,8 @@
use PHPStan\Rules\PhpDoc\InvalidPhpDocTagValueRule;
use PHPStan\Rules\PhpDoc\InvalidPHPStanDocTagRule;
use PHPStan\Rules\PhpDoc\InvalidThrowsPhpDocValueRule;
use PHPStan\Rules\PhpDoc\MethodAssertRule;
use PHPStan\Rules\PhpDoc\MethodConditionalReturnTypeRule;
use PHPStan\Rules\PhpDoc\UnresolvableTypeHelper;
use PHPStan\Rules\Properties\ExistingClassesInPropertiesRule;
use PHPStan\Rules\Properties\MissingPropertyTypehintRule;
Expand Down Expand Up @@ -186,6 +196,8 @@ private function getRuleRegistry(Container $container): RuleRegistry
$propertyTagCheck = new PropertyTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true);
$reflector = $container->getService('stubReflector');
$relativePathHelper = $container->getService('simpleRelativePathHelper');
$assertRuleHelper = $container->getByType(AssertRuleHelper::class);
$conditionalReturnTypeRuleHelper = $container->getByType(ConditionalReturnTypeRuleHelper::class);

$rules = [
// level 0
Expand Down Expand Up @@ -237,6 +249,14 @@ private function getRuleRegistry(Container $container): RuleRegistry
new PropertyTagRule($propertyTagCheck),
new PropertyTagTraitRule($propertyTagCheck, $reflectionProvider),
new PropertyTagTraitUseRule($propertyTagCheck),
new EnumAncestorsRule($genericAncestorsCheck, $crossCheckInterfacesHelper),
new EnumTemplateTypeRule(),
new PropertyVarianceRule($varianceCheck),
new UsedTraitsRule($fileTypeMapper, $genericAncestorsCheck),
new FunctionAssertRule($assertRuleHelper),
new MethodAssertRule($assertRuleHelper),
new FunctionConditionalReturnTypeRule($conditionalReturnTypeRuleHelper),
new MethodConditionalReturnTypeRule($conditionalReturnTypeRuleHelper),

// level 6
new MissingFunctionParameterTypehintRule($missingTypehintCheck),
Expand Down
5 changes: 0 additions & 5 deletions stubs/ReflectionClass.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
class ReflectionClass
{

/**
* @var class-string<T>
*/
public $name;

/**
* @param T|class-string<T> $argument
* @throws ReflectionException
Expand Down
10 changes: 0 additions & 10 deletions stubs/ext-ds.stub
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,6 @@ final class Map implements Collection, ArrayAccess
*/
final class Pair implements JsonSerializable
{
/**
* @var TKey
*/
public $key;

/**
* @var TValue
*/
public $value;

/**
* @param TKey $key
* @param TValue $value
Expand Down

3 comments on commit bf19914

@ondrejmirtes
Copy link
Member Author

Choose a reason for hiding this comment

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

/cc @jiripudil Do you think it'd somehow be possible to bring these stub properties back? Right now they report:

 ------ ----------------------------------------------------------------------------------------
  Line   stubs/ReflectionClass.stub
 ------ ----------------------------------------------------------------------------------------
  12     Template type T is declared as covariant, but occurs in invariant position in property
         ReflectionClass::$name.
 ------ ----------------------------------------------------------------------------------------

 ------ ----------------------------------------------------------------------------------------------------------
  Line   stubs/ext-ds.stub
 ------ ----------------------------------------------------------------------------------------------------------
  359    Template type TKey is declared as covariant, but occurs in invariant position in property Ds\Pair::$key.
  364    Template type TValue is declared as covariant, but occurs in invariant position in property
         Ds\Pair::$value.
 ------ ----------------------------------------------------------------------------------------------------------

@jiripudil
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, I believe ReflectionClass::$name could be marked as readonly (or @readonly), which it effectively is. That will make it a covariant position.

With Ds\Pair, you can actually write into the properties in runtime, so the correct way would be to make the template types invariant

@ondrejmirtes
Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you! See 544101b

Please sign in to comment.