Skip to content

Commit 7ac48f5

Browse files
committed
feat: Use null|TData when the initial data is null
1 parent 2f97c6a commit 7ac48f5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

stubs/Symfony/Component/Form/FormFactoryInterface.stub

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface FormFactoryInterface
1414
* @param TData $data
1515
* @param array<string, mixed> $options
1616
*
17-
* @phpstan-return FormInterface<TData>
17+
* @phpstan-return ($data is null ? FormInterface<null|TData> : FormInterface<TData>)
1818
*
1919
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
2020
*/
@@ -27,8 +27,8 @@ interface FormFactoryInterface
2727
* @param class-string<TFormType> $type
2828
* @param TData $data
2929
* @param array<string, mixed> $options
30-
*
31-
* @phpstan-return FormInterface<TData>
30+
*
31+
* @phpstan-return ($data is null ? FormInterface<null|TData> : FormInterface<TData>)
3232
*
3333
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
3434
*/

tests/Stubs/Symfony/Component/Form/FormFactoryAwareClass.php

+13
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,22 @@ public function doSomething(): void
2222
$form = $this->formFactory->create(DataClassType::class, new DataClass());
2323
$data = $form->getData();
2424
$this->thisOnlyAcceptsDataClass($data);
25+
$this->thisOnlyAcceptsDataClassOrNull($data);
26+
}
27+
28+
public function doSomethingNullable(): void
29+
{
30+
$form = $this->formFactory->create(DataClassType::class);
31+
$data = $form->getData();
32+
// $this->thisOnlyAcceptsDataClass($data); // ERROR!
33+
$this->thisOnlyAcceptsDataClassOrNull($data);
2534
}
2635

2736
private function thisOnlyAcceptsDataClass(DataClass $data): void
2837
{
2938
}
39+
40+
private function thisOnlyAcceptsDataClassOrNull(?DataClass $data): void
41+
{
42+
}
3043
}

0 commit comments

Comments
 (0)