From 14eec8c011b856eee4d744a2a3f709db1e1858bd Mon Sep 17 00:00:00 2001 From: Zachary Lund Date: Mon, 12 Aug 2024 11:03:46 -0500 Subject: [PATCH] Add stub for AbstractController::createForm() --- extension.neon | 2 ++ .../Controller/AbstractController.stub | 24 +++++++++++++++++++ .../Service/ServiceSubscriberInterface.stub | 7 ++++++ tests/Type/Symfony/data/form_data_type.php | 18 ++++++++++++++ 4 files changed, 51 insertions(+) create mode 100644 stubs/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.stub create mode 100644 stubs/Symfony/Contracts/Service/ServiceSubscriberInterface.stub diff --git a/extension.neon b/extension.neon index e58d668f..512f9908 100644 --- a/extension.neon +++ b/extension.neon @@ -27,6 +27,7 @@ parameters: - stubs/Psr/Cache/CacheException.stub - stubs/Psr/Cache/CacheItemInterface.stub - stubs/Psr/Cache/InvalidArgumentException.stub + - stubs/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.stub - stubs/Symfony/Bundle/FrameworkBundle/KernelBrowser.stub - stubs/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.stub - stubs/Symfony/Bundle/FrameworkBundle/Test/TestContainer.stub @@ -103,6 +104,7 @@ parameters: - stubs/Symfony/Contracts/Cache/CacheInterface.stub - stubs/Symfony/Contracts/Cache/CallbackInterface.stub - stubs/Symfony/Contracts/Cache/ItemInterface.stub + - stubs/Symfony/Contracts/Service/ServiceSubscriberInterface.stub - stubs/Twig/Node/Node.stub parametersSchema: diff --git a/stubs/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.stub b/stubs/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.stub new file mode 100644 index 00000000..075dce6d --- /dev/null +++ b/stubs/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.stub @@ -0,0 +1,24 @@ + + * @template TData + * + * @param class-string $type + * @param TData $data + * @param array $options + * + * @phpstan-return ($data is null ? FormInterface : FormInterface) + */ + protected function createForm(string $type, $data = null, array $options = []): FormInterface + { + } +} diff --git a/stubs/Symfony/Contracts/Service/ServiceSubscriberInterface.stub b/stubs/Symfony/Contracts/Service/ServiceSubscriberInterface.stub new file mode 100644 index 00000000..8860e239 --- /dev/null +++ b/stubs/Symfony/Contracts/Service/ServiceSubscriberInterface.stub @@ -0,0 +1,7 @@ +createForm(DataClassType::class, new DataClass()); + assertType('GenericFormDataType\DataClass', $form->getData()); + } + + public function doSomethingNullable(): void + { + $form = $this->createForm(DataClassType::class); + assertType('GenericFormDataType\DataClass|null', $form->getData()); + } + +}