Repository: symfony/symfony
File: src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php (PHP)

Code before:
            $payload['reply_to'] = $emails[0];
        }

        $customArguments = [];
        $categories = [];

        foreach ($email->getHeaders()->all() as $name => $header) {
            // these headers can't be overwritten according to Sendgrid docs
            // see https://sendgrid.api-docs.io/v3.0/mail-send/mail-send-errors#-Headers-Errors
            if (\in_array($name, ['x-sg-id', 'x-sg-eid', 'received', 'dkim-signature', 'content-transfer-encoding', 'from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'reply-to'], true)) {
                continue;
            }

            if ($header instanceof TagHeader) {
                if (10 === \count($categories)) {
                    throw new TransportException(\sprintf('Too many "%s" instances present in the email headers. Sendgrid does not accept more than 10 categories on an email.', TagHeader::class));
                }
                $categories[] = mb_substr($header->getValue(), 0, 255);
            } elseif ($header instanceof MetadataHeader) {
                $customArguments[$header->getKey()] = $header->getValue();
            } elseif ($header instanceof SuppressionGroupHeader) {
                $payload['asm'] = [
                    'group_id' => $header->getGroupId(),
                ];
                $groupsToDisplay = $header->getGroupsToDisplay();
                if ($groupsToDisplay) {
                    $payload['asm']['groups_to_display'] = $groupsToDisplay;
                }
            } else {
                $payload['headers'][$header->getName()] = $header->getBodyAsString();
            }
        }

        if (\count($categories) > 0) {
            $payload['categories'] = $categories;
        }

        if (\count($customArguments) > 0) {
            $personalization['custom_args'] = $customArguments;
        }

        $payload['personalizations'][] = $personalization;

        return $payload;
    }

    private function getContent(Email $email): array
    {
        $content = [];
        if (null !== $text = $email->getTextBody()) {
            $content[] = ['type' => 'text/plain', 'value' => $text];

Review comment (suggestion):
```suggestion
                if ($groupsToDisplay = $header->getGroupsToDisplay()) {
```

Code after:
            $payload['reply_to'] = $emails[0];
        }

        $customArguments = [];
        $categories = [];

        foreach ($email->getHeaders()->all() as $name => $header) {
            // these headers can't be overwritten according to Sendgrid docs
            // see https://sendgrid.api-docs.io/v3.0/mail-send/mail-send-errors#-Headers-Errors
            if (\in_array($name, ['x-sg-id', 'x-sg-eid', 'received', 'dkim-signature', 'content-transfer-encoding', 'from', 'to', 'cc', 'bcc', 'subject', 'content-type', 'reply-to'], true)) {
                continue;
            }

            if ($header instanceof TagHeader) {
                if (10 === \count($categories)) {
                    throw new TransportException(\sprintf('Too many "%s" instances present in the email headers. Sendgrid does not accept more than 10 categories on an email.', TagHeader::class));
                }
                $categories[] = mb_substr($header->getValue(), 0, 255);
            } elseif ($header instanceof MetadataHeader) {
                $customArguments[$header->getKey()] = $header->getValue();
            } elseif ($header instanceof SuppressionGroupHeader) {
                $payload['asm'] = [
                    'group_id' => $header->getGroupId(),
                ];
                if ($groupsToDisplay = $header->getGroupsToDisplay()) {
                    $payload['asm']['groups_to_display'] = $groupsToDisplay;
                }
            } else {
                $payload['headers'][$header->getName()] = $header->getBodyAsString();
            }
        }

        if (\count($categories) > 0) {
            $payload['categories'] = $categories;
        }

        if (\count($customArguments) > 0) {
            $personalization['custom_args'] = $customArguments;
        }

        $payload['personalizations'][] = $personalization;

        return $payload;
    }

    private function getContent(Email $email): array
    {
        $content = [];
        if (null !== $text = $email->getTextBody()) {
            $content[] = ['type' => 'text/plain', 'value' => $text];
        }