Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query result type is not recognized if the alias is "attribute" #566

Closed
julienfalque opened this issue May 17, 2024 · 2 comments
Closed

Comments

@julienfalque
Copy link
Contributor

When using the query builder, if the queried entity has alias "attribute", the type of the query result is considered mixed instead of list<Entity>. For example, with the following code:

namespace App\Repository;

use App\Entity\Attribute;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @extends ServiceEntityRepository<Attribute>
 */
class AttributeRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Attribute::class);
    }

    /**
     * @return list<Attribute>
     */
    public function all(): array
    {
        return $this->createQueryBuilder('attribute')
            ->getQuery()
            ->getResult();
    }
}

PHPStan will report:

------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   src/App/Repository/AttributeRepository.php                                                                                          
 ------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  20     Method App\Repository\AttributeRepository::all() should return list<App\Entity\Attribute> but returns mixed.  
         💡 mixed is not a list.                                                                                                                                             
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------------------------

Changing the alias to any other value fixes the error.

@ondrejmirtes
Copy link
Member

We found the culprit. Please subscribe to #608.

Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants