diff --git a/.php_cs b/.php_cs index c40df9c..4bc5c37 100644 --- a/.php_cs +++ b/.php_cs @@ -18,9 +18,9 @@ return PhpCsFixer\Config::create() '@Symfony' => true, 'strict_param' => true, 'array_syntax' => ['syntax' => 'short'], - 'declare_strict_types' => false, // true + 'declare_strict_types' => true, 'no_empty_phpdoc' => true, - 'no_superfluous_phpdoc_tags' => false, // true + 'no_superfluous_phpdoc_tags' => true, 'header_comment' => [ 'commentType' => 'comment', 'header' => $header, diff --git a/src/Api/Attachment.php b/src/Api/Attachment.php index 0e1a171..4de1d52 100644 --- a/src/Api/Attachment.php +++ b/src/Api/Attachment.php @@ -1,5 +1,7 @@ uri = $uri; diff --git a/src/HttpClient/RequestBuilder.php b/src/HttpClient/RequestBuilder.php index 4027c80..7885479 100644 --- a/src/HttpClient/RequestBuilder.php +++ b/src/HttpClient/RequestBuilder.php @@ -1,5 +1,7 @@ string|resource|StreamInterface, - * 'name' => string, - * 'filename'=> string (optional) - * 'headers' => array (optinal) ['header-name' => 'header-value'] - * ) + * @param array|string|null $body Request body. If body is an array we will send a as multipart stream request. + * If array, each array *item* MUST look like: + * array ( + * 'content' => string|resource|StreamInterface, + * 'name' => string, + * 'filename'=> string (optional) + * 'headers' => array (optinal) ['header-name' => 'header-value'] + * ) * * @return RequestInterface */ diff --git a/src/Hydrator/ArrayHydrator.php b/src/Hydrator/ArrayHydrator.php index 80f00e7..5b453e4 100644 --- a/src/Hydrator/ArrayHydrator.php +++ b/src/Hydrator/ArrayHydrator.php @@ -1,5 +1,7 @@ domain)) { throw new RuntimeException('You must call BatchMessage::setDomain before sending messages.'); - } elseif (empty($message['from'])) { - throw MissingRequiredParameter::create('from'); - } elseif (empty($message['to'])) { - throw MissingRequiredParameter::create('to'); - } elseif (empty($message['subject'])) { - throw MissingRequiredParameter::create('subject'); - } elseif (empty($message['text']) && empty($message['html'])) { - throw MissingRequiredParameter::create('text" or "html'); - } else { - $message['recipient-variables'] = json_encode($this->batchRecipientAttributes); - $response = $this->api->send($this->domain, $message); - - $this->batchRecipientAttributes = []; - $this->counters['recipients']['to'] = 0; - $this->counters['recipients']['cc'] = 0; - $this->counters['recipients']['bcc'] = 0; - unset($this->message['to']); - - $this->messageIds[] = $response->getId(); } + + if (empty($message['from'])) { + throw MissingRequiredParameter::create('from'); + } + + if (empty($message['to'])) { + throw MissingRequiredParameter::create('to'); + } + + if (empty($message['subject'])) { + throw MissingRequiredParameter::create('subject'); + } + + if (empty($message['text']) && empty($message['html'])) { + throw MissingRequiredParameter::create('text" or "html'); + } + + $message['recipient-variables'] = json_encode($this->batchRecipientAttributes); + $response = $this->api->send($this->domain, $message); + + $this->batchRecipientAttributes = []; + $this->counters['recipients']['to'] = 0; + $this->counters['recipients']['cc'] = 0; + $this->counters['recipients']['bcc'] = 0; + unset($this->message['to']); + + $this->messageIds[] = $response->getId(); } /** diff --git a/src/Message/Exceptions/LimitExceeded.php b/src/Message/Exceptions/LimitExceeded.php index 4463d1d..fae151d 100644 --- a/src/Message/Exceptions/LimitExceeded.php +++ b/src/Message/Exceptions/LimitExceeded.php @@ -1,5 +1,7 @@ message['v:'.$customName] = json_encode($data); @@ -408,10 +385,6 @@ class MessageBuilder return $this; } - /** - * @param string $parameterName - * @param mixed $data - */ public function addCustomParameter(string $parameterName, $data): self { if (isset($this->message[$parameterName])) { diff --git a/src/Model/ApiResponse.php b/src/Model/ApiResponse.php index aa22485..82a86b5 100644 --- a/src/Model/ApiResponse.php +++ b/src/Model/ApiResponse.php @@ -1,5 +1,7 @@ messageHeaders; } - /** - * @param array $messageHeaders - */ private function setMessageHeaders(array $messageHeaders) { $this->messageHeaders = $messageHeaders; diff --git a/src/Model/PaginationResponse.php b/src/Model/PaginationResponse.php index 4c56d2d..503b0dc 100644 --- a/src/Model/PaginationResponse.php +++ b/src/Model/PaginationResponse.php @@ -1,5 +1,7 @@ time = $time; diff --git a/src/Model/Suppression/BaseResponse.php b/src/Model/Suppression/BaseResponse.php index 97a2c00..bc5516a 100644 --- a/src/Model/Suppression/BaseResponse.php +++ b/src/Model/Suppression/BaseResponse.php @@ -1,5 +1,7 @@ createdAt; } - /** - * @param \DateTime $createdAt - */ private function setCreatedAt(\DateTime $createdAt) { $this->createdAt = $createdAt; diff --git a/src/Model/Suppression/Bounce/CreateResponse.php b/src/Model/Suppression/Bounce/CreateResponse.php index 38842ac..65b950d 100644 --- a/src/Model/Suppression/Bounce/CreateResponse.php +++ b/src/Model/Suppression/Bounce/CreateResponse.php @@ -1,5 +1,7 @@ createdAt; } - /** - * @param \DateTime $createdAt - */ private function setCreatedAt(\DateTime $createdAt) { $this->createdAt = $createdAt; diff --git a/src/Model/Suppression/Complaint/CreateResponse.php b/src/Model/Suppression/Complaint/CreateResponse.php index f480ffd..4a8f909 100644 --- a/src/Model/Suppression/Complaint/CreateResponse.php +++ b/src/Model/Suppression/Complaint/CreateResponse.php @@ -1,5 +1,7 @@ createdAt; } - /** - * @param \DateTime $createdAt - */ private function setCreatedAt(\DateTime $createdAt) { $this->createdAt = $createdAt; diff --git a/src/Model/Tag/DeleteResponse.php b/src/Model/Tag/DeleteResponse.php index b108980..930f51f 100644 --- a/src/Model/Tag/DeleteResponse.php +++ b/src/Model/Tag/DeleteResponse.php @@ -1,5 +1,7 @@ webhook = $webhook; } /** - * @param array $data - * * @return ShowResponse */ public static function create(array $data) diff --git a/src/Model/Webhook/UpdateResponse.php b/src/Model/Webhook/UpdateResponse.php index f50d70b..61aa669 100644 --- a/src/Model/Webhook/UpdateResponse.php +++ b/src/Model/Webhook/UpdateResponse.php @@ -1,5 +1,7 @@ requestUri = $requestUri; } - /** - * @param array $requestHeaders - */ public function setRequestHeaders(array $requestHeaders) { $this->requestHeaders = $requestHeaders; } - /** - * @param mixed $requestBody - */ public function setRequestBody($requestBody) { $this->requestBody = $requestBody; diff --git a/tests/Api/WebhookTest.php b/tests/Api/WebhookTest.php index c581d0e..1387843 100644 --- a/tests/Api/WebhookTest.php +++ b/tests/Api/WebhookTest.php @@ -1,5 +1,7 @@ getApiInstance('key-3ax6xnjp29jd6fds4gc373sgvjxteol0'); - $timestamp = '1403645220'; + $timestamp = 1403645220; $token = '5egbgr1vjgqxtrnp65xfznchgdccwh5d6i09vijqi3whgowmn6'; $signature = '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33'; @@ -37,7 +39,7 @@ class WebhookTest extends TestCase public function testVerifyWebhookBad() { $api = $this->getApiInstance('key-3ax6xnjp29jd6fds4gc373sgvjxteol0'); - $timestamp = '1403645220'; + $timestamp = 1403645220; $token = 'owyldpe6nxhmrn78epljl6bj0orrki1u3d2v5e6cnlmmuox8jr'; $signature = '9cfc5c41582e51246e73c88d34db3af0a3a2692a76fbab81492842f000256d33'; diff --git a/tests/Exception/HttpClientExceptionTest.php b/tests/Exception/HttpClientExceptionTest.php index 33e53d8..0756855 100644 --- a/tests/Exception/HttpClientExceptionTest.php +++ b/tests/Exception/HttpClientExceptionTest.php @@ -1,5 +1,7 @@ assertEquals(1, count($message['to'])); } - public function testAttributeResetOnEndBatchMessage() + public function testRecipientAttributeResetOnEndBatchMessage() { $this->batchMessage->addToRecipient('test-user@samples.mailgun.org', ['first' => 'Test', 'last' => 'User']); $this->batchMessage->setFromAddress('samples@mailgun.org', ['first' => 'Test', 'last' => 'User']); @@ -117,7 +119,9 @@ class BatchMessageTest extends MailgunTestCase $this->batchMessage->setTextBody('This is the text body of the message!'); $this->batchMessage->finalize(); $message = NSA::getProperty($this->batchMessage, 'message'); - $this->assertTrue(true, empty($message)); + + $this->assertTrue(empty($message['to'])); + $this->assertNotEmpty($message); } public function testDefaultIDInVariables() diff --git a/tests/Message/MessageBuilderTest.php b/tests/Message/MessageBuilderTest.php index 6891d50..9d50fe8 100644 --- a/tests/Message/MessageBuilderTest.php +++ b/tests/Message/MessageBuilderTest.php @@ -1,5 +1,7 @@ assertEquals(['o:campaign' => ['ABC123', 'XYZ987', 'TUV456']], $message); } - public function testAddCampaignIdInteger() - { - $this->messageBuilder->addCampaignId(1111); - $this->messageBuilder->addCampaignId(2222); - $message = $this->messageBuilder->getMessage(); - $this->assertSame(['o:campaign' => ['1111', '2222']], $message); - } - public function testSetDkim() { $this->messageBuilder->setDkim(true); diff --git a/tests/Model/BaseModelTest.php b/tests/Model/BaseModelTest.php index 562a7e3..79808c7 100644 --- a/tests/Model/BaseModelTest.php +++ b/tests/Model/BaseModelTest.php @@ -1,5 +1,7 @@