Skip to content

[TypeDeclarationDocblocks] Use unique type when all types equals on AddReturnDocblockForCommonObjectDenominatorRector#7254

Merged
samsonasik merged 2 commits intomainfrom
use-single-type
Sep 12, 2025
Merged

[TypeDeclarationDocblocks] Use unique type when all types equals on AddReturnDocblockForCommonObjectDenominatorRector#7254
samsonasik merged 2 commits intomainfrom
use-single-type

Conversation

@samsonasik
Copy link
Member

Given the folllowing code:

final class UniqueTypeSingle
{
    public function getExtensions(): array
    {
        return [
            new \DateTime('now'),
            new \DateTime('tomorrow'),
        ];
    }
}

It got diff:

+    /**
+     * @return \DateTimeInterface[]
+     */
     public function getExtensions(): array
     {
        return [
            new \DateTime('now'),
            new \DateTime('tomorrow'),
        ];
    }

which should use \DateTime only, as all unique type is single. On complex application, it can cause PHPStan notice that not instanceof type

  - '#Parameter \#1 \$abc of method XYZ expects \DateTimeInterface, \DateTime given#'
  🪪 argument.type

…ddReturnDocblockForCommonObjectDenominatorRector
@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @TomasVotruba

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit 9e93740 into main Sep 12, 2025
49 checks passed
@samsonasik samsonasik deleted the use-single-type branch September 12, 2025 12:13
@github-actions
Copy link
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant