Skip to content

ObjectManager interface lacks of @throws annotation. #340

@VincentLanglet

Description

@VincentLanglet

When looking at the ObjectManager interface
https://github.com/doctrine/persistence/blob/3.2.x/src/Persistence/ObjectManager.php
there si none @throws annotation for each methods.

When looking at the ORM implementation
https://github.com/doctrine/orm/blob/2.16.x/lib/Doctrine/ORM/EntityManager.php
or the ODM implementation
https://github.com/doctrine/mongodb-odm/blob/2.6.x/lib/Doctrine/ODM/MongoDB/DocumentManager.php
a lot of exception are thrown in those methods.

The interface contract should be about the @param, @return but also @throws.
If I write

public function foo(ObjectManager $om) {
    $om->flush();
}

I have no help from PHPStorm or PHPStan that an exception can be thrown and that I should try/catch the call sometimes.

When I write

public function foo(EntityManager $om) {
    $om->flush();
}

PHPStan analysis help me to handle correctly exceptions (see https://phpstan.org/blog/bring-your-exceptions-under-control).

What could be great would be to

  • have some Doctrine\Persistence\Exception class or interface
  • add @throws Doctrine\Persistence\Exception to methods which can throws exception
  • extends/implements this exception in the ORM/ODM repository for exception thrown in the ObjectManager methods

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions