doctrine / doctrine/persistence

ObjectManager interface lacks of `@throws` annotation.

Open
#340 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
4k
Forks
76
Avg merge
3d 20h
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

Research direction

Start with src/Persistence/ObjectManager.php and compare each method with the ORM EntityManager.php and ODM DocumentManager.php implementations linked in the issue. Determine the required exception contract and scope across the persistence, ORM, and ODM repositories; done means the agreed exception annotations and hierarchy are consistently represented and validated by the relevant analysis tools.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend-api-design, databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.