Skip to content

Conversation

@VincentLanglet
Copy link
Contributor

No description provided.

@VincentLanglet VincentLanglet force-pushed the formOptions branch 4 times, most recently from 7c21546 to b8b9ebc Compare December 24, 2024 13:17

public function doSomethingWithInvalidOption(): void
{
$form = $this->formFactory->create(DataClassType::class, new DataClass(), ['required' => 42]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to get an error here saying I pass an integer when a string is expected because DataClassType is

AbstractType<DataClass, array{required: string, optional: int}> 

I thought it would have been reported by the CallMethodsRuleTest.

What do I miss @ondrejmirtes ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please recreate the scenario in a minimal way on phpstan.org/try so I don't have to hold all the interfaces and Symfony classes in my head.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.
You already helped me with phpstan/phpstan#12372 (comment).

But I discovered that in Symfony, that the required options in the Factory::create methods and the certains options in the buildForm $options are not exactly the same.

So this would give something like
https://phpstan.org/r/2fc552e7-506e-46a5-aba0-69287a5b8d3e

I dunno if it's possible to have something better than

@implements FormTypeInterface< * object, * array{required: string, optional?: int, defined?: bool}, * array{required: string, optional: int, defined?: bool} * > 

/**
* @template TData
* @template TOptions of array<string, mixed>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be optional, otherwise it's a BC break. See phpstan/phpstan-src#3457

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants