Skip to content

[PHPStanStaticTypeMapper] Handle crash on DowngradeMixedTypeDeclarationRector for PHPStan\Type\ConditionalType#4625

Merged
TomasVotruba merged 5 commits intomainfrom
handle-crash-mixed
Jul 31, 2023
Merged

[PHPStanStaticTypeMapper] Handle crash on DowngradeMixedTypeDeclarationRector for PHPStan\Type\ConditionalType#4625
TomasVotruba merged 5 commits intomainfrom
handle-crash-mixed

Conversation

@samsonasik
Copy link
Copy Markdown
Member

@samsonasik samsonasik requested a review from TomasVotruba as a code owner July 31, 2023 12:59
@samsonasik
Copy link
Copy Markdown
Member Author

@TomasVotruba I added ConditionalTypeMapper, it currently produce invalid result:

     /**
      * @template TValue of array<array|scalar>|scalar
      *
-     * @return (TValue is scalar ? array|scalar : array<array|scalar>)
+     * @return (Rector\Core\Tests\Issues\IssueConditionalType\Fixture\TValue is (bool | float | int | string) ? (array | bool | float | int | string) : array<(array | bool | float | int | string)>)
      */

Comment on lines +45 to +52
$type = TypeTraverser::map($type, static function (Type $type, callable $traverse): Type {
if ($type instanceof \PHPStan\Type\ObjectType && $type->getClassReflection() === null) {
$newClassName = Strings::after($type->getClassName(), '\\', -1);
$type = new \PHPStan\Type\ObjectType($newClassName);
}

return $traverse($type);
});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@TomasVotruba this is to tweak the @template usage

@samsonasik
Copy link
Copy Markdown
Member Author

@leoloso it fixed, with tweak, I am not sure if this will be an elegant solution, but just looking at the use case, it seems the way to resolve it.

@samsonasik
Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@TomasVotruba TomasVotruba merged commit 881d0b7 into main Jul 31, 2023
@TomasVotruba TomasVotruba deleted the handle-crash-mixed branch July 31, 2023 14:18
@TomasVotruba
Copy link
Copy Markdown
Member

Thanks 🙏

@leoloso
Copy link
Copy Markdown
Contributor

leoloso commented Aug 1, 2023

@samsonasik it's working well, thanks! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

System error: "Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper::mapToPHPStanPhpDocTypeNode

4 participants