Skip to content

Commit

Permalink
Add stub for AbstractController::createForm()
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharylund authored and ondrejmirtes committed Aug 13, 2024
1 parent ee88a01 commit 14eec8c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Symfony\Bundle\FrameworkBundle\Controller;

use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormTypeInterface;
use Symfony\Contracts\Service\ServiceSubscriberInterface;

abstract class AbstractController implements ServiceSubscriberInterface
{
/**
* @template TFormType of FormTypeInterface<TData>
* @template TData
*
* @param class-string<TFormType> $type
* @param TData $data
* @param array<string, mixed> $options
*
* @phpstan-return ($data is null ? FormInterface<null|TData> : FormInterface<TData>)
*/
protected function createForm(string $type, $data = null, array $options = []): FormInterface
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Symfony\Contracts\Service;

interface ServiceSubscriberInterface
{
}
18 changes: 18 additions & 0 deletions tests/Type/Symfony/data/form_data_type.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace GenericFormDataType;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand Down Expand Up @@ -73,3 +74,20 @@ public function doSomethingNullable(): void
}

}

class FormController extends AbstractController
{

public function doSomething(): void
{
$form = $this->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());
}

}

0 comments on commit 14eec8c

Please sign in to comment.