From dd7c1d2361dab7bd2a7994d1c790280f5ff0858d Mon Sep 17 00:00:00 2001 From: Nyholm Date: Wed, 9 Jan 2019 20:32:09 +0100 Subject: [PATCH] Added new CS rules Declare strict and no superfluous phpdoc --- .php_cs | 4 +- src/Api/Attachment.php | 2 + src/Api/Domain.php | 4 +- src/Api/Event.php | 5 +- src/Api/HttpApi.php | 7 +-- src/Api/Ip.php | 2 + src/Api/MailingList.php | 2 + src/Api/MailingList/Member.php | 2 + src/Api/Message.php | 7 ++- src/Api/Pagination.php | 2 + src/Api/Route.php | 2 + src/Api/Stats.php | 2 + src/Api/Suppression.php | 2 + src/Api/Suppression/Bounce.php | 2 + src/Api/Suppression/Complaint.php | 2 + src/Api/Suppression/Unsubscribe.php | 2 + src/Api/Tag.php | 2 + src/Api/Webhook.php | 2 + src/Assert.php | 2 + src/Exception.php | 2 + src/Exception/HttpClientException.php | 2 + src/Exception/HttpServerException.php | 2 + src/Exception/HydrationException.php | 2 + src/Exception/InvalidArgumentException.php | 2 + src/Exception/UnknownErrorException.php | 2 + src/HttpClient/HttpClientConfigurator.php | 2 + src/HttpClient/Plugin/History.php | 2 + src/HttpClient/Plugin/ReplaceUriPlugin.php | 5 +- src/HttpClient/RequestBuilder.php | 21 ++++---- src/Hydrator/ArrayHydrator.php | 2 + src/Hydrator/Hydrator.php | 4 +- src/Hydrator/ModelHydrator.php | 2 + src/Hydrator/NoopHydrator.php | 2 + src/Mailgun.php | 2 + src/Message/BatchMessage.php | 52 +++++++++++-------- src/Message/Exceptions/LimitExceeded.php | 2 + .../Exceptions/MissingRequiredParameter.php | 2 + src/Message/Exceptions/RuntimeException.php | 2 + src/Message/Exceptions/TooManyRecipients.php | 2 + src/Message/MessageBuilder.php | 45 ++++------------ src/Model/ApiResponse.php | 3 +- src/Model/Attachment/Attachment.php | 2 + src/Model/Domain/AbstractDomainResponse.php | 5 +- src/Model/Domain/ConnectionResponse.php | 4 +- src/Model/Domain/CreateCredentialResponse.php | 4 +- src/Model/Domain/CreateResponse.php | 2 + src/Model/Domain/CredentialResponse.php | 4 +- src/Model/Domain/CredentialResponseItem.php | 11 ++-- src/Model/Domain/DeleteCredentialResponse.php | 4 +- src/Model/Domain/DeleteResponse.php | 4 +- src/Model/Domain/DnsRecord.php | 4 +- src/Model/Domain/Domain.php | 17 +++--- src/Model/Domain/IndexResponse.php | 4 +- src/Model/Domain/ShowResponse.php | 5 +- src/Model/Domain/UpdateConnectionResponse.php | 4 +- src/Model/Domain/UpdateCredentialResponse.php | 4 +- src/Model/Domain/VerifyResponse.php | 2 + src/Model/Event/Event.php | 4 +- src/Model/Event/EventResponse.php | 3 +- src/Model/Ip/IndexResponse.php | 2 + src/Model/Ip/ShowResponse.php | 2 + src/Model/Ip/UpdateResponse.php | 2 + src/Model/MailingList/CreateResponse.php | 4 +- src/Model/MailingList/DeleteResponse.php | 2 + src/Model/MailingList/MailingList.php | 15 +++--- .../MailingList/Member/CreateResponse.php | 3 +- .../MailingList/Member/DeleteResponse.php | 3 +- .../MailingList/Member/IndexResponse.php | 5 +- src/Model/MailingList/Member/Member.php | 4 +- src/Model/MailingList/Member/ShowResponse.php | 2 + .../MailingList/Member/UpdateResponse.php | 3 +- src/Model/MailingList/PagesResponse.php | 5 +- src/Model/MailingList/ShowResponse.php | 2 + src/Model/MailingList/UpdateResponse.php | 4 +- src/Model/Message/SendResponse.php | 4 +- src/Model/Message/ShowResponse.php | 7 +-- src/Model/PaginationResponse.php | 2 + src/Model/PagingProvider.php | 2 + src/Model/Route/Action.php | 3 +- src/Model/Route/Response/CreateResponse.php | 3 +- src/Model/Route/Response/DeleteResponse.php | 4 +- src/Model/Route/Response/IndexResponse.php | 2 + src/Model/Route/Response/ShowResponse.php | 4 +- src/Model/Route/Response/UpdateResponse.php | 5 +- src/Model/Route/Route.php | 3 +- src/Model/Stats/AllResponse.php | 4 +- src/Model/Stats/AllResponseItem.php | 5 +- src/Model/Stats/TotalResponse.php | 6 +-- src/Model/Stats/TotalResponseItem.php | 11 +--- src/Model/Suppression/BaseResponse.php | 4 +- src/Model/Suppression/Bounce/Bounce.php | 7 +-- .../Suppression/Bounce/CreateResponse.php | 2 + .../Suppression/Bounce/DeleteResponse.php | 2 + .../Suppression/Bounce/IndexResponse.php | 5 +- src/Model/Suppression/Bounce/ShowResponse.php | 2 + src/Model/Suppression/Complaint/Complaint.php | 7 +-- .../Suppression/Complaint/CreateResponse.php | 2 + .../Suppression/Complaint/DeleteResponse.php | 2 + .../Suppression/Complaint/IndexResponse.php | 5 +- .../Suppression/Complaint/ShowResponse.php | 2 + .../Unsubscribe/CreateResponse.php | 2 + .../Unsubscribe/DeleteResponse.php | 2 + .../Suppression/Unsubscribe/IndexResponse.php | 4 +- .../Suppression/Unsubscribe/ShowResponse.php | 2 + .../Suppression/Unsubscribe/Unsubscribe.php | 7 +-- src/Model/Tag/DeleteResponse.php | 4 +- src/Model/Tag/IndexResponse.php | 5 +- src/Model/Tag/ShowResponse.php | 2 + src/Model/Tag/StatisticsResponse.php | 13 ++--- src/Model/Tag/Tag.php | 4 +- src/Model/Tag/UpdateResponse.php | 4 +- src/Model/Webhook/BaseResponse.php | 5 +- src/Model/Webhook/CreateResponse.php | 2 + src/Model/Webhook/DeleteResponse.php | 2 + src/Model/Webhook/IndexResponse.php | 4 +- src/Model/Webhook/ShowResponse.php | 7 +-- src/Model/Webhook/UpdateResponse.php | 2 + tests/Api/AttachmentTest.php | 2 + tests/Api/DomainTest.php | 2 + tests/Api/EventTest.php | 2 + tests/Api/MailingList/MemberTest.php | 2 + tests/Api/MailingListTest.php | 2 + tests/Api/MessageTest.php | 2 + tests/Api/RouteTest.php | 2 + tests/Api/StatsTest.php | 2 + tests/Api/Suppression/BounceTest.php | 2 + tests/Api/Suppression/ComplaintTest.php | 2 + tests/Api/Suppression/UnsubscribeTest.php | 2 + tests/Api/SuppressionTest.php | 2 + tests/Api/TagTest.php | 2 + tests/Api/TestCase.php | 10 +--- tests/Api/WebhookTest.php | 6 ++- tests/Exception/HttpClientExceptionTest.php | 2 + tests/HttpClient/RequestBuilderTest.php | 2 + tests/MailgunTestCase.php | 2 + tests/Message/BatchMessageTest.php | 8 ++- tests/Message/MessageBuilderTest.php | 10 +--- tests/Model/BaseModelTest.php | 2 + tests/Model/Domain/ConnectionResponseTest.php | 2 + .../Domain/CreateCredentialResponseTest.php | 2 + tests/Model/Domain/CreateResponseTest.php | 2 + .../Domain/CredentialResponseItemTest.php | 2 + tests/Model/Domain/CredentialResponseTest.php | 2 + .../Domain/DeleteCredentialResponseTest.php | 2 + tests/Model/Domain/DeleteResponseTest.php | 2 + tests/Model/Domain/DnsRecordTest.php | 2 + tests/Model/Domain/DomainTest.php | 2 + tests/Model/Domain/IndexResponseTest.php | 2 + tests/Model/Domain/ShowResponseTest.php | 2 + .../Domain/UpdateConnectionResponseTest.php | 2 + .../Domain/UpdateCredentialResponseTest.php | 2 + tests/Model/Domain/VerifyResponseTest.php | 2 + tests/Model/Event/EventResponseTest.php | 2 + tests/Model/Ip/IndexResponseTest.php | 2 + tests/Model/Ip/ShowResponseTest.php | 2 + tests/Model/Ip/UpdateResponseTest.php | 2 + .../Model/MailingList/CreateResponseTest.php | 2 + .../Model/MailingList/DeleteResponseTest.php | 2 + .../MailingList/Member/CreateResponseTest.php | 2 + .../MailingList/Member/DeleteResponseTest.php | 2 + .../MailingList/Member/IndexResponseTest.php | 2 + .../MailingList/Member/UpdateResponseTest.php | 2 + tests/Model/MailingList/PagesResponseTest.php | 2 + .../Model/MailingList/UpdateResponseTest.php | 2 + tests/Model/Message/SendResponseTest.php | 2 + tests/Model/Route/CreateResponseTest.php | 2 + tests/Model/Route/IndexResponseTest.php | 2 + tests/Model/Route/ShowResponseTest.php | 2 + tests/Model/Stats/TotalResponseTest.php | 2 + .../Unsubscribe/UnsubscribeTest.php | 2 + tests/Model/Tag/IndexResponseTest.php | 2 + tests/Model/Tag/TagTest.php | 2 + 172 files changed, 411 insertions(+), 263 deletions(-) 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 @@