You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minor symfony#59061 [Mime] Fix wrong PHPDoc in FormDataPart constructor (MaximePinot)
This PR was merged into the 6.4 branch.
Discussion
----------
[Mime] Fix wrong PHPDoc in `FormDataPart` constructor
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | no
| New feature? | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License | MIT
I believe the PHPDoc is wrong.
As far as I understand, the `FormDataPart` expects instances of `TextPart`:
```php
if (!\is_string($item) && !$item instanceof TextPart) {
throw new InvalidArgumentException(sprintf('The value of the form field "%s" can only be a string, an array, or an instance of TextPart, "%s" given.', $fieldName, get_debug_type($item)));
}
```
https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Mime/Part/Multipart/FormDataPart.php#L74
The following code is rejected by PHPStan while it works:
```php
final readonly class Foo
{
public function bar(): void
{
new FormDataPart([
new TextPart('baz'),
]);
}
}
```
```shell
------ -------------------------------------------------------------------------------------------------------------------
Line src/Foo.php
------ -------------------------------------------------------------------------------------------------------------------
14 Parameter symfony#1 $fields of class Symfony\Component\Mime\Part\Multipart\FormDataPart constructor expects
array<array|string|Symfony\Component\Mime\Part\DataPart>, array<int, Symfony\Component\Mime\Part\TextPart> given.
------ -------------------------------------------------------------------------------------------------------------------
```
(cc `@B`-Galati)
Commits
-------
886d4ed [Mime] Fix wrong PHPDoc in `FormDataPart` constructor
0 commit comments