minor #31837 Change type hints (fabpot)

This PR was merged into the 4.3 branch.

Discussion
----------

Change type hints

| Q             | A
| ------------- | ---
| Branch?       | 4.3 for features / 3.4, 4.2 or 4.3 for bug fixes <!-- see below -->
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

see https://github.com/symfony/symfony/pull/31774#discussion_r289597824

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/roadmap):
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against branch 4.4.
 - Legacy code removals go to the master branch.
-->

Commits
-------

d56ae06ca3 changed type hints
This commit is contained in:
Fabien Potencier 2019-06-04 11:23:46 +02:00
commit 5a88e4cfd6
3 changed files with 2 additions and 20 deletions

View File

@ -11,12 +11,10 @@
namespace Symfony\Component\Mailer;
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
use Symfony\Component\Mailer\Exception\LogicException;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\RawMessage;
/**
* @author Fabien Potencier <fabien@symfony.com>
@ -31,13 +29,8 @@ final class DelayedSmtpEnvelope extends SmtpEnvelope
private $recipientsSet = false;
private $message;
public function __construct(RawMessage $message)
public function __construct(Message $message)
{
if (!$message instanceof Message) {
// FIXME: parse the raw message to create the envelope?
throw new InvalidArgumentException(sprintf('Unable to create an SmtpEnvelope from a "%s" message.', RawMessage::class));
}
$this->message = $message;
}

View File

@ -91,10 +91,4 @@ class SmtpEnvelopeTest extends TestCase
$e = SmtpEnvelope::create(new Message($headers));
$this->assertEquals([new Address('to@symfony.com'), new Address('cc@symfony.com'), new Address('bcc@symfony.com')], $e->getRecipients());
}
public function testCreateWithRawMessage()
{
$this->expectException(\InvalidArgumentException::class);
SmtpEnvelope::create(new RawMessage(''));
}
}

View File

@ -28,17 +28,12 @@ final class MessageConverter
/**
* @throws RuntimeException when unable to convert the message to an email
*/
public static function toEmail(RawMessage $message): Email
public static function toEmail(Message $message): Email
{
if ($message instanceof Email) {
return $message;
}
if (RawMessage::class === \get_class($message)) {
// FIXME: parse the raw message to create the envelope?
throw new RuntimeException(sprintf('Unable to create an Email from an instance of "%s" as it is not supported yet.', RawMessage::class));
}
// try to convert to a "simple" Email instance
$body = $message->getBody();
if ($body instanceof TextPart) {