sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

[RFC] Add generics for implementations of `ProxyQueryInterface` at `AdminInterface` and its related classes #7526

Closed phansys closed 2 years ago

phansys commented 2 years ago

Feature Request

Add generics for implementations of ProxyQueryInterface at AdminInterface and its related classes.

My personal use case with the ORM model manager is the following:

$proxyQuery = $this->createQuery();
\assert($proxyQuery instanceof \Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface);
$qb = $proxyQuery->getQueryBuilder();

// $qb->...

Currently, I have to call \assert($proxyQuery instanceof \Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface) in order to make explicit the type for the proxy query.

VincentLanglet commented 2 years ago

You mean AdminInterface<object, ProxyQueryInterface> ?

I understand the idea and why you want to do this. But I feel like it will be a mess.

For instance, getDatagrid is returning a DatagridInterface<ProxyQueryInterface>, it will be DatagridInterface<P>. But someone could ask the same for Datagrid, and we'll have to add a Generic D for the DatagridInterface.

Also same could be done for the ModelManagerInterface, and it will require a Generic M for this. And we could add the ProxyQueryInterface in the Generic of ModelManager since there is this method https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/Model/ModelManagerInterface.php#L87...

And don't know where we should stop if we start this. And since it's a BC-break for static analysis users, this should be thought a lot before.

As a workaround, I use the annotation

/** 
 * @method Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQueryInterface createQuery()
 */

On top on the admin class