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

Code before:
        ];
        if ($emails = array_map($addressStringifier, $email->getCc())) {
            $personalization['cc'] = $emails;
        }
        if ($emails = array_map($addressStringifier, $email->getBcc())) {
            $personalization['bcc'] = $emails;
        }
        if ($emails = array_map($addressStringifier, $email->getReplyTo())) {
            // Email class supports an array of reply-to addresses,
            // but SendGrid only supports a single address
            $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 ('send-at' === $name) {
                if (!$header instanceof DateHeader) {
                    throw new TransportException(\sprintf('The Send-At header should be a "%s" instance to deduce the correct timestamp.', DateHeader::class));
                }
                $payload['send_at'] = $header->getDateTime()->getTimestamp();
            } elseif ($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 ($categories) {
            $payload['categories'] = $categories;
        }


Review comment (suggestion):
```suggestion
                    throw new TransportException(\sprintf('The "Send-At" header must be a "%s" instance.', DateHeader::class));
```

Code after:
        ];
        if ($emails = array_map($addressStringifier, $email->getCc())) {
            $personalization['cc'] = $emails;
        }
        if ($emails = array_map($addressStringifier, $email->getBcc())) {
            $personalization['bcc'] = $emails;
        }
        if ($emails = array_map($addressStringifier, $email->getReplyTo())) {
            // Email class supports an array of reply-to addresses,
            // but SendGrid only supports a single address
            $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 ('send-at' === $name) {
                if (!$header instanceof DateHeader) {
                    throw new TransportException(\sprintf('The "Send-At" header must be a "%s" instance.', DateHeader::class));
                }
                $payload['send_at'] = $header->getDateTime()->getTimestamp();
            } elseif ($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 ($categories) {
            $payload['categories'] = $categories;
        }