create generic EntityInterface #7006

Open
opened 2026-01-22 15:43:00 +01:00 by admin · 0 comments
Owner

Originally created by @arderyp on GitHub (Jul 16, 2022).

Feature Request

Q A
New Feature yes
RFC ?
BC Break probably

Summary

For those of us who use PHPStan/Psalm, which are increasing in popularity, there should be an EntityInterface. It could be blank, or maybe have a single getId() method. This would resolved a lot of the mixed typing with Doctrine. I have done this myself, and all of my entities implement it, and I've created a stub to get around some of the mixed mess, for example:

<?php

declare(strict_types=1);

namespace Doctrine\ORM;

use App\Entity\EntityInterface;


abstract class AbstractQuery
{
    public const HYDRATE_OBJECT = 1;

    /**
     * @param string|int|null $hydrationMode
     * @phpstan-ignore-next-line [STUB] we are overriding the return type
     */
    public function getOneOrNullResult($hydrationMode = null): ?EntityInterface;

    /**
     * see: https://github.com/phpstan/phpstan-doctrine/issues/301
     * @param string|int $hydrationMode
     * @phpstan-ignore-next-line [STUB] we are overriding the return type
     */
    public function getResult($hydrationMode = self::HYDRATE_OBJECT): array;

    /**
     * @param string|int|null $hydrationMode
     * @phpstan-ignore-next-line [STUB] we are overriding the return type
     */
    public function getSingleResult($hydrationMode = null): EntityInterface;
}
Originally created by @arderyp on GitHub (Jul 16, 2022). ### Feature Request <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | New Feature | yes | RFC | ? | BC Break | probably #### Summary <!-- Provide a summary of the feature you would like to see implemented. --> For those of us who use PHPStan/Psalm, which are increasing in popularity, there should be an EntityInterface. It could be blank, or maybe have a single `getId()` method. This would resolved a lot of the `mixed` typing with Doctrine. I have done this myself, and all of my entities implement it, and I've created a stub to get around some of the `mixed` mess, for example: ``` <?php declare(strict_types=1); namespace Doctrine\ORM; use App\Entity\EntityInterface; abstract class AbstractQuery { public const HYDRATE_OBJECT = 1; /** * @param string|int|null $hydrationMode * @phpstan-ignore-next-line [STUB] we are overriding the return type */ public function getOneOrNullResult($hydrationMode = null): ?EntityInterface; /** * see: https://github.com/phpstan/phpstan-doctrine/issues/301 * @param string|int $hydrationMode * @phpstan-ignore-next-line [STUB] we are overriding the return type */ public function getResult($hydrationMode = self::HYDRATE_OBJECT): array; /** * @param string|int|null $hydrationMode * @phpstan-ignore-next-line [STUB] we are overriding the return type */ public function getSingleResult($hydrationMode = null): EntityInterface; } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7006