Skip to content

[Mime] Fix wrong PHPDoc in FormDataPart constructor #59061

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

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

MaximePinot
Copy link
Contributor

Q A
Branch? 6.4
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

I believe the PHPDoc is wrong.

As far as I understand, the FormDataPart expects instances of TextPart:

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:

final readonly class Foo
{
    public function bar(): void
    {
        new FormDataPart([
            new TextPart('baz'),
        ]);
    }
}
 ------ ------------------------------------------------------------------------------------------------------------------- 
  Line   src/Foo.php                                                                                     
 ------ ------------------------------------------------------------------------------------------------------------------- 
  14     Parameter #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)

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

LGTM

@nicolas-grekas
Copy link
Member

Thank you @MaximePinot.

@nicolas-grekas nicolas-grekas merged commit 8804980 into symfony:6.4 Dec 2, 2024
10 checks passed
@MaximePinot MaximePinot deleted the patch-1 branch December 2, 2024 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants