Skip to content

Conversation

@TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Sep 12, 2025

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];
Copy link
Member

@samsonasik samsonasik Sep 12, 2025

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
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
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
Member

Choose a reason for hiding this comment

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

Copy link
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
Member Author

Choose a reason for hiding this comment

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

I see.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants