CoreShop icon indicating copy to clipboard operation
CoreShop copied to clipboard

Generics for repositories and repository interfaces

Open dkarlovi opened this issue 2 years ago • 1 comments

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? yes

Doctrine's \Doctrine\Persistence\ObjectRepository supports generics. Since CS interfaces extend it, it would make sense to denote they're generic too.

For example, it would mean adding

/**
 * @template T
 *
 * @extends ObjectRepository<T>
 */
interface CoreShop\Component\Resource\Repository\RepositoryInterface extends ObjectRepository

and then

/** 
 * @template T of PaymentProviderInterface
 *
 * @extends RepositoryInterface<T>
 */
interface PaymentProviderRepositoryInterface extends RepositoryInterface

This would also make many of the types inferred by default by Psalm / PHPStan and many PHPDoc blocks could be removed.

dkarlovi avatar Apr 22 '22 15:04 dkarlovi

Additional example: https://psalm.dev/r/11594ec601

dkarlovi avatar Apr 25 '22 08:04 dkarlovi