Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 14eec8c

Browse files
zacharylundondrejmirtes
authored andcommitted
Add stub for AbstractController::createForm()
1 parent ee88a01 commit 14eec8c

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

‎extension.neon‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ parameters:
2727
- stubs/Psr/Cache/CacheException.stub
2828
- stubs/Psr/Cache/CacheItemInterface.stub
2929
- stubs/Psr/Cache/InvalidArgumentException.stub
30+
- stubs/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.stub
3031
- stubs/Symfony/Bundle/FrameworkBundle/KernelBrowser.stub
3132
- stubs/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.stub
3233
- stubs/Symfony/Bundle/FrameworkBundle/Test/TestContainer.stub
@@ -103,6 +104,7 @@ parameters:
103104
- stubs/Symfony/Contracts/Cache/CacheInterface.stub
104105
- stubs/Symfony/Contracts/Cache/CallbackInterface.stub
105106
- stubs/Symfony/Contracts/Cache/ItemInterface.stub
107+
- stubs/Symfony/Contracts/Service/ServiceSubscriberInterface.stub
106108
- stubs/Twig/Node/Node.stub
107109

108110
parametersSchema:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\FrameworkBundle\Controller;
4+
5+
use Symfony\Component\Form\FormInterface;
6+
use Symfony\Component\Form\FormTypeInterface;
7+
use Symfony\Contracts\Service\ServiceSubscriberInterface;
8+
9+
abstract class AbstractController implements ServiceSubscriberInterface
10+
{
11+
/**
12+
* @template TFormType of FormTypeInterface<TData>
13+
* @template TData
14+
*
15+
* @param class-string<TFormType> $type
16+
* @param TData $data
17+
* @param array<string, mixed> $options
18+
*
19+
* @phpstan-return ($data is null ? FormInterface<null|TData> : FormInterface<TData>)
20+
*/
21+
protected function createForm(string $type, $data = null, array $options = []): FormInterface
22+
{
23+
}
24+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Contracts\Service;
4+
5+
interface ServiceSubscriberInterface
6+
{
7+
}

‎tests/Type/Symfony/data/form_data_type.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace GenericFormDataType;
44

5+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
56
use Symfony\Component\Form\AbstractType;
67
use Symfony\Component\Form\Extension\Core\Type\NumberType;
78
use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -73,3 +74,20 @@ public function doSomethingNullable(): void
7374
}
7475

7576
}
77+
78+
class FormController extends AbstractController
79+
{
80+
81+
public function doSomething(): void
82+
{
83+
$form = $this->createForm(DataClassType::class, new DataClass());
84+
assertType('GenericFormDataType\DataClass', $form->getData());
85+
}
86+
87+
public function doSomethingNullable(): void
88+
{
89+
$form = $this->createForm(DataClassType::class);
90+
assertType('GenericFormDataType\DataClass|null', $form->getData());
91+
}
92+
93+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /