Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stub for AbstractController::createForm() #403

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{
/**
zacharylund marked this conversation as resolved.
Show resolved Hide resolved
* @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());
}

}