Skip to content

Commit

Permalink
Add @throws annotation on EntityManagerInterface::flush
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Nov 8, 2023
1 parent 90e60ba commit b1e4a69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
23 changes: 16 additions & 7 deletions stubs/EntityManagerInterface.stub
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,20 @@ interface EntityManagerInterface extends ObjectManager
*/
public function copy($entity, $deep = false);

/**
* @template T of object
* @phpstan-param class-string<T> $className
*
* @phpstan-return ClassMetadata<T>
*/
public function getClassMetadata($className);
/**
* @return void
*
* @throws ORMException
* @throws \Doctrine\DBAL\Exception\UniqueConstraintViolationException
*/
public function flush();

/**
* @template T of object
* @phpstan-param class-string<T> $className
*
* @phpstan-return ClassMetadata<T>
*/
public function getClassMetadata($className);

}
8 changes: 8 additions & 0 deletions tests/Rules/Exceptions/data/unthrown-exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ class FooFacade
/** @var \Doctrine\ORM\EntityManager */
private $entityManager;

/** @var \Doctrine\ORM\EntityManagerInterface */
private $entityManagerInterface;

public function doFoo(): void
{
try {
$this->entityManager->flush();
} catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
// pass
}
try {
$this->entityManagerInterface->flush();
} catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
// pass
}
}

}

0 comments on commit b1e4a69

Please sign in to comment.