bug #39812 Make EmailMessage & SmsMessage transport nullable (odolbeau)

This PR was merged into the 5.1 branch.

Discussion
----------

Make EmailMessage & SmsMessage transport nullable

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| License       | MIT

Ideally, this should have been done in #38361 as it's exactly the same problem: the `transport` method can be called with `null` with deserializing a message from json (for example).

Commits
-------

d98aca06d0 Make EmailMessage & SmsMessage transport nullable
This commit is contained in:
Fabien Potencier 2021-01-14 08:17:33 +01:00
commit 41697467bc
2 changed files with 5 additions and 2 deletions

View File

@ -97,11 +97,14 @@ final class EmailMessage implements MessageInterface
/**
* @return $this
*/
public function transport(string $transport): self
public function transport(?string $transport): self
{
if (!$this->message instanceof Email) {
throw new LogicException('Cannot set a Transport on a RawMessage instance.');
}
if (null === $transport) {
return $this;
}
$this->message->getHeaders()->addTextHeader('X-Transport', $transport);

View File

@ -81,7 +81,7 @@ final class SmsMessage implements MessageInterface
/**
* @return $this
*/
public function transport(string $transport): self
public function transport(?string $transport): self
{
$this->transport = $transport;