From 158351b6689737e068c9959a7530da0e5ef7c44a Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 8 Nov 2023 10:41:44 +0100 Subject: [PATCH 1/2] Add throws annotation on interface --- stubs/EntityManagerInterface.stub | 8 ++++++++ tests/Rules/Exceptions/data/unthrown-exception.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/stubs/EntityManagerInterface.stub b/stubs/EntityManagerInterface.stub index 1f76e18f..af586164 100644 --- a/stubs/EntityManagerInterface.stub +++ b/stubs/EntityManagerInterface.stub @@ -60,6 +60,14 @@ interface EntityManagerInterface extends ObjectManager */ public function copy($entity, $deep = false); + /** + * @return void + * + * @throws ORMException + * @throws \Doctrine\DBAL\Exception\UniqueConstraintViolationException + */ + public function flush(); + /** * @template T of object * @phpstan-param class-string $className diff --git a/tests/Rules/Exceptions/data/unthrown-exception.php b/tests/Rules/Exceptions/data/unthrown-exception.php index ecc1f522..c69e2b48 100644 --- a/tests/Rules/Exceptions/data/unthrown-exception.php +++ b/tests/Rules/Exceptions/data/unthrown-exception.php @@ -8,6 +8,9 @@ class FooFacade /** @var \Doctrine\ORM\EntityManager */ private $entityManager; + /** @var \Doctrine\ORM\EntityManagerInterface */ + private $entityManagerInterface; + public function doFoo(): void { try { @@ -15,6 +18,11 @@ public function doFoo(): void } catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) { // pass } + try { + $this->entityManagerInterface->flush(); + } catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) { + // pass + } } } From ecba08064aa38fe021eed04db5a392ba4a43a341 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 8 Nov 2023 17:25:31 +0100 Subject: [PATCH 2/2] Fix indent --- stubs/EntityManagerInterface.stub | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/stubs/EntityManagerInterface.stub b/stubs/EntityManagerInterface.stub index af586164..8ab8db8a 100644 --- a/stubs/EntityManagerInterface.stub +++ b/stubs/EntityManagerInterface.stub @@ -60,19 +60,20 @@ interface EntityManagerInterface extends ObjectManager */ public function copy($entity, $deep = false); - /** - * @return void - * - * @throws ORMException - * @throws \Doctrine\DBAL\Exception\UniqueConstraintViolationException - */ - public function flush(); + /** + * @return void + * + * @throws ORMException + * @throws \Doctrine\DBAL\Exception\UniqueConstraintViolationException + */ + public function flush(); + + /** + * @template T of object + * @phpstan-param class-string $className + * + * @phpstan-return ClassMetadata + */ + public function getClassMetadata($className); - /** - * @template T of object - * @phpstan-param class-string $className - * - * @phpstan-return ClassMetadata - */ - public function getClassMetadata($className); }