镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[type-declaration-docblocks] Add AddReturnDocblockForCommonObjectDenominatorRector - #7249

Merged
TomasVotruba merged 3 commits into
mainfrom
tv-return-object-type-denominator
Sep 12, 2025
Merged

TomasVotruba merged 3 commits into
mainfrom
tv-return-object-type-denominator

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Sep 12, 2025 •

Copy link
Copy Markdown
Member

This rule adds @return array based on shared interface/object in an array of objects 👍

final class ReturnOfObjects
{
+   /**
+    * @return ExtensionInterface[]
+    */
    public function getExtensions(): array
    {
        return [
            new FirstExtension(),
            new SecondExtension()
        ];
    }
}

@TomasVotruba
TomasVotruba force-pushed the tv-return-object-type-denominator branch from 366dafd to 4b949f8 Compare September 12, 2025 09:38
@TomasVotruba TomasVotruba changed the title tv return object type denominator [type-declaration-docblocks] Add AddReturnDocblockForCommonObjectDenominatorRector Sep 12, 2025
@TomasVotruba
TomasVotruba force-pushed the tv-return-object-type-denominator branch 2 times, most recently from d37b773 to f5fdb86 Compare September 12, 2025 09:47
@TomasVotruba
TomasVotruba enabled auto-merge (squash) September 12, 2025 09:47
@TomasVotruba
TomasVotruba force-pushed the tv-return-object-type-denominator branch from f5fdb86 to dbdf9de Compare September 12, 2025 09:48
@TomasVotruba
TomasVotruba merged commit 81464fa into main Sep 12, 2025
49 checks passed
@TomasVotruba
TomasVotruba deleted the tv-return-object-type-denominator branch September 12, 2025 09:49
return null;
}

return $returnsScoped[0];

@samsonasik samsonasik Sep 12, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this needs count() for only returns 1 return:

Suggested change
return $returnsScoped[0];
return count($returnsScoped) === 1 ? $returnsScoped[0] : null;

multiple returns should be skipped on this case for this rule purpose.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

$returnsScoped = $this->betterNodeFinder->findReturnsScoped($functionLike);
if (! $this->returnAnalyzer->hasOnlyReturnWithExpr($functionLike, $returnsScoped)) {
return null;
}

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.

@samsonasik I think this method already covers it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hasOnlyReturnWithExpr is verify that All returns has Expr.

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.

I see.

@github-actions

Copy link
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

2 participants