From 9bfe75a9551dd67ee2798087cb161a00e6380431 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:35:21 +0200 Subject: [PATCH 1/9] Added PHPStorm .idea configuration folder to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e26f45e..24def93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.phar /vendor/ composer.lock +.idea/ From c969a51879b2df7e3f7752890f449f85f497fed9 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:39:45 +0200 Subject: [PATCH 2/9] Implemented absolute namespace --- SwiftMailer/MailjetTransport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftMailer/MailjetTransport.php b/SwiftMailer/MailjetTransport.php index fd113fe..7b2f025 100644 --- a/SwiftMailer/MailjetTransport.php +++ b/SwiftMailer/MailjetTransport.php @@ -30,7 +30,7 @@ class MailjetTransport implements Swift_Transport { protected $mailjetClient = null; /** - * @var Mailjet\MailjetSwiftMailer\SwiftMailer\MessageFormat\MessageFormatStrategyInterface + * @var \Mailjet\MailjetSwiftMailer\SwiftMailer\MessageFormat\MessageFormatStrategyInterface */ public $messageFormat; From c4fd3d6fafc91fab3690e5435f730e47ac24a6f8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:45:06 +0200 Subject: [PATCH 3/9] Removed unnecessary variable initializations --- SwiftMailer/MailjetTransport.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/SwiftMailer/MailjetTransport.php b/SwiftMailer/MailjetTransport.php index 7b2f025..1ce351b 100644 --- a/SwiftMailer/MailjetTransport.php +++ b/SwiftMailer/MailjetTransport.php @@ -122,7 +122,6 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { return 0; } } - $sendCount = 0; // extract Mailjet Message from SwiftMailer Message $mailjetMessage = $this->messageFormat->getMailjetMessage($message); @@ -167,7 +166,6 @@ public function bulkSend(array $messages, &$failedRecipients = null) { $this->resultApi = null; $failedRecipients = (array) $failedRecipients; $bulkContainer = ['Messages' => []]; - $sendCount = 0; foreach ($messages as $message) { // extract Mailjet Message from SwiftMailer Message $mailjetMessage = $this->messageFormat->getMailjetMessage($message); From f371da8e28456abe31ce66632ad5826a024c9613 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:47:40 +0200 Subject: [PATCH 4/9] Added correct PHPDoc comments --- SwiftMailer/MailjetTransport.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SwiftMailer/MailjetTransport.php b/SwiftMailer/MailjetTransport.php index 1ce351b..fb95687 100644 --- a/SwiftMailer/MailjetTransport.php +++ b/SwiftMailer/MailjetTransport.php @@ -112,6 +112,7 @@ public function ping() { * @param Swift_Mime_Message $message * @param null $failedRecipients * @return int Number of messages sent + * @throws \Swift_TransportException */ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { $this->resultApi = null; @@ -157,9 +158,10 @@ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { } /** - * @param array $message (of Swift_Mime_Message) + * @param array $messages (of Swift_Mime_Message) * @param null $failedRecipients * @return int Number of messages sent + * @throws \Swift_TransportException */ public function bulkSend(array $messages, &$failedRecipients = null) { @@ -257,7 +259,8 @@ protected function createMailjetClient() { /** * Inject an external Mailjet\Client * @method setExternalMailjetClient - * @param \Mailjet\Client $client + * @param \Mailjet\Client $client + * @return \Mailjet\Client */ public function setExternalMailjetClient(\Mailjet\Client $client) { From a0b1bb66cc3f35439cca6806b4eabecf7774b10e Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:49:23 +0200 Subject: [PATCH 5/9] Added correct missing PHPDoc parameter --- SwiftMailer/MailjetTransport.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SwiftMailer/MailjetTransport.php b/SwiftMailer/MailjetTransport.php index fb95687..5b58677 100644 --- a/SwiftMailer/MailjetTransport.php +++ b/SwiftMailer/MailjetTransport.php @@ -67,9 +67,11 @@ class MailjetTransport implements Swift_Transport { protected $resultApi; /** + * MailjetTransport constructor. * @param Swift_Events_EventDispatcher $eventDispatcher * @param string $apiKey * @param string $apiSecret + * @param bool $call * @param array $clientOptions */ public function __construct(Swift_Events_EventDispatcher $eventDispatcher, $apiKey = null, $apiSecret = null, $call = true, array $clientOptions = []) { From e0d5e1709e76f859b25c700cd5e45dee4993651a Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:50:23 +0200 Subject: [PATCH 6/9] Removed unnecessary comment --- SwiftMailer/MailjetTransport.php | 1 - 1 file changed, 1 deletion(-) diff --git a/SwiftMailer/MailjetTransport.php b/SwiftMailer/MailjetTransport.php index 5b58677..9e7bd87 100644 --- a/SwiftMailer/MailjetTransport.php +++ b/SwiftMailer/MailjetTransport.php @@ -201,7 +201,6 @@ public function bulkSend(array $messages, &$failedRecipients = null) { $resultStatus = Swift_Events_SendEvent::RESULT_FAILED; } } catch (\Exception $e) { - //$failedRecipients = $mailjetMessage['Recipients']; $sendCount = 0; $resultStatus = Swift_Events_SendEvent::RESULT_FAILED; } From dbd2cbfeec9da19c24faeab3843e2a635885b2ed Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:52:54 +0200 Subject: [PATCH 7/9] Removed variable $resultStatus and connected logic, which was never used --- SwiftMailer/MailjetTransport.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/SwiftMailer/MailjetTransport.php b/SwiftMailer/MailjetTransport.php index 9e7bd87..0ac39aa 100644 --- a/SwiftMailer/MailjetTransport.php +++ b/SwiftMailer/MailjetTransport.php @@ -192,17 +192,9 @@ public function bulkSend(array $messages, &$failedRecipients = null) { try { // send API call $this->resultApi = $this->mailjetClient->post(Resources::$Email, ['body' => $bulkContainer]); - $sendCount = $this->findNumberOfSentMails(); - // get result - if ($this->resultApi->success()) { - $resultStatus = Swift_Events_SendEvent::RESULT_SUCCESS; - } else { - $resultStatus = Swift_Events_SendEvent::RESULT_FAILED; - } } catch (\Exception $e) { $sendCount = 0; - $resultStatus = Swift_Events_SendEvent::RESULT_FAILED; } return $sendCount; From 0fe3690333d01ce481cd2475f95084581bce43c4 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:56:48 +0200 Subject: [PATCH 8/9] Added correct typehinting --- SwiftMailer/MailjetTransport.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SwiftMailer/MailjetTransport.php b/SwiftMailer/MailjetTransport.php index 0ac39aa..d46464f 100644 --- a/SwiftMailer/MailjetTransport.php +++ b/SwiftMailer/MailjetTransport.php @@ -2,6 +2,7 @@ namespace Mailjet\MailjetSwiftMailer\SwiftMailer; +use Mailjet\Response; use \Swift_Events_EventDispatcher; use \Swift_Events_EventListener; use \Swift_Events_SendEvent; @@ -62,7 +63,7 @@ class MailjetTransport implements Swift_Transport { protected $clientOptions; /** - * @var array|null + * @var array|null|Response */ protected $resultApi; @@ -187,8 +188,7 @@ public function bulkSend(array $messages, &$failedRecipients = null) { } } // Create mailjetClient - $mailjetClient = $this->createMailjetClient(); - + $this->createMailjetClient(); try { // send API call $this->resultApi = $this->mailjetClient->post(Resources::$Email, ['body' => $bulkContainer]); @@ -342,7 +342,7 @@ public function getClientOptions() { } /** - * @return null|array + * @return array|Response|null */ public function getResultApi() { return $this->resultApi; From b7047c5696b9ecddc6e374a568e4d2c12cb3a966 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 10 Apr 2018 10:58:05 +0200 Subject: [PATCH 9/9] Optimized namespace --- SwiftMailer/MailjetTransport.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SwiftMailer/MailjetTransport.php b/SwiftMailer/MailjetTransport.php index d46464f..c6e106e 100644 --- a/SwiftMailer/MailjetTransport.php +++ b/SwiftMailer/MailjetTransport.php @@ -3,6 +3,7 @@ namespace Mailjet\MailjetSwiftMailer\SwiftMailer; use Mailjet\Response; +use Mailjet\Client; use \Swift_Events_EventDispatcher; use \Swift_Events_EventListener; use \Swift_Events_SendEvent; @@ -243,10 +244,10 @@ protected function createMailjetClient() { } if (isset($this->clientOptions)) { - return new \Mailjet\Client($this->apiKey, $this->apiSecret, $this->call, $this->clientOptions); + return new Client($this->apiKey, $this->apiSecret, $this->call, $this->clientOptions); } - return new \Mailjet\Client($this->apiKey, $this->apiSecret, $this->call); + return new Client($this->apiKey, $this->apiSecret, $this->call); } /** @@ -255,7 +256,7 @@ protected function createMailjetClient() { * @param \Mailjet\Client $client * @return \Mailjet\Client */ - public function setExternalMailjetClient(\Mailjet\Client $client) + public function setExternalMailjetClient(Client $client) { $this->mailjetClient = $client; return $this->mailjetClient;