From 9b606c762aaab06c0c6d1d56598e0acb763e5b2a Mon Sep 17 00:00:00 2001 From: Oleksandr Mykhailenko Date: Sat, 20 Jul 2024 19:53:03 +0300 Subject: [PATCH 1/2] Laravel package improvements. --- README.md | 15 +++- composer.json | 3 +- src/Contracts/CampaignContract.php | 25 +++++- src/Contracts/CampaignDraftContract.php | 107 ++++++++++++++++++------ src/Services/CampaignDraftService.php | 89 ++++++++++---------- src/Services/CampaignService.php | 15 ++-- 6 files changed, 165 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index c0c2dd6..5a8098f 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,17 @@ Please also set your email from address and name. ] ``` +## Laravel 11.0+ +In the file `example-app/bootstrap/providers.php` +```php +use Mailjet\LaravelMailjet\MailjetServiceProvider; + +return [ + App\Providers\AppServiceProvider::class, + MailjetServiceProvider::class, +]; +```` + * In the aliases array: ```php @@ -128,7 +139,3 @@ public function handle(ContactsV4Service $contactsV4Service) ... } ``` - -## ToDo - -* Add additional unit tests to increase code coverage. diff --git a/composer.json b/composer.json index 6e74e2c..d4d373a 100644 --- a/composer.json +++ b/composer.json @@ -31,8 +31,9 @@ ], "require": { "php": "^7.1.3|^8.0", - "laravel/framework": "~5.1|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", + "laravel/framework": "^9.0|^10.0|^11.0", "mailjet/mailjet-apiv3-php": "^1.5.6|^1.5", + "symfony/http-client": "^7.1", "symfony/mailjet-mailer": "^6.0" }, "require-dev": { diff --git a/src/Contracts/CampaignContract.php b/src/Contracts/CampaignContract.php index 65eb6b9..feec406 100644 --- a/src/Contracts/CampaignContract.php +++ b/src/Contracts/CampaignContract.php @@ -8,11 +8,28 @@ interface CampaignContract { - public function getAllCampaigns(array $filters = null); + /** + * @param array|null $filters + * @return array + */ + public function getAllCampaigns(array $filters = null): array; - public function findByCampaignId(string $id); + /** + * @param string $id + * @return array + */ + public function findByCampaignId(string $id): array; - public function findByNewsletterId(string $id); + /** + * @param string $id + * @return array + */ + public function findByNewsletterId(string $id): array; - public function updateCampaign(string $id, Campaign $campaign); + /** + * @param string $id + * @param Campaign $campaign + * @return array + */ + public function updateCampaign(string $id, Campaign $campaign): array; } diff --git a/src/Contracts/CampaignDraftContract.php b/src/Contracts/CampaignDraftContract.php index 11bdc64..e73db56 100644 --- a/src/Contracts/CampaignDraftContract.php +++ b/src/Contracts/CampaignDraftContract.php @@ -8,29 +8,86 @@ interface CampaignDraftContract { - public function getAllCampaignDrafts(array $filters = null); - - public function findByCampaignDraftId(string $id); - - public function create(CampaignDraft $campaignDraft); - - public function update(string $id, CampaignDraft $campaignDraft); - - public function getDetailContent(string $id); - - public function createDetailContent(string $id, array $content); - - public function getSchedule(string $id); - - public function scheduleCampaign(string $id, string $date); - - public function updateCampaignSchedule(string $id, string $date); - - public function removeSchedule(string $id); - - public function sendCampaign(string $id); - - public function testCampaign(string $id, array $recipients); - - public function getCampaignStatus(string $id); + /** + * @param array|null $filters + * @return array + */ + public function getAllCampaignDrafts(array $filters = null): array; + + /** + * @param string $id + * @return array + */ + public function findByCampaignDraftId(string $id): array; + + /** + * @param CampaignDraft $campaignDraft + * @return array + */ + public function create(CampaignDraft $campaignDraft): array; + + /** + * @param string $id + * @param CampaignDraft $campaignDraft + * @return array + */ + public function update(string $id, CampaignDraft $campaignDraft): array; + + /** + * @param string $id + * @return array + */ + public function getDetailContent(string $id): array; + + /** + * @param string $id + * @param array $content + * @return array + */ + public function createDetailContent(string $id, array $content): array; + + /** + * @param string $id + * @return array + */ + public function getSchedule(string $id): array; + + /** + * @param string $id + * @param string $date + * @return array + */ + public function scheduleCampaign(string $id, string $date): array; + + /** + * @param string $id + * @param string $date + * @return array + */ + public function updateCampaignSchedule(string $id, string $date): array; + + /** + * @param string $id + * @return array + */ + public function removeSchedule(string $id): array; + + /** + * @param string $id + * @return array + */ + public function sendCampaign(string $id): array; + + /** + * @param string $id + * @param array $recipients + * @return array + */ + public function testCampaign(string $id, array $recipients): array; + + /** + * @param string $id + * @return array + */ + public function getCampaignStatus(string $id): array; } diff --git a/src/Services/CampaignDraftService.php b/src/Services/CampaignDraftService.php index bfa613d..c463b07 100644 --- a/src/Services/CampaignDraftService.php +++ b/src/Services/CampaignDraftService.php @@ -27,9 +27,9 @@ public function __construct(MailjetService $mailjet) /** * List campaign draft resources available for this apikey. - * + * @param array|null $filters * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function getAllCampaignDrafts(array $filters = null): array { @@ -44,12 +44,11 @@ public function getAllCampaignDrafts(array $filters = null): array /** * Access a given CampaignDraft resource. - * * @param string $id - * * @return array + * @throws MailjetException */ - public function findByCampaignDraftId(string $id) + public function findByCampaignDraftId(string $id): array { $response = $this->mailjet->get(Resources::$Campaigndraft, ['id' => $id]); @@ -63,10 +62,10 @@ public function findByCampaignDraftId(string $id) /** * create a new fresh CampaignDraft - * * @param Campaigndraft $campaignDraft + * @throws MailjetException */ - public function create(CampaignDraft $campaignDraft) + public function create(CampaignDraft $campaignDraft): array { $response = $this->mailjet->post(Resources::$Campaigndraft, ['body' => $campaignDraft->format()]); @@ -79,11 +78,12 @@ public function create(CampaignDraft $campaignDraft) /** * Update one specific campaigndraft resource - * - * @param int $id + * @param string $id * @param Campaigndraft $campaignDraft + * @return array + * @throws MailjetException */ - public function update($id, CampaignDraft $campaignDraft) + public function update(string $id, CampaignDraft $campaignDraft): array { $response = $this->mailjet->put(Resources::$Campaigndraft, ['id' => $id, 'body' => $campaignDraft->format()]); @@ -96,12 +96,11 @@ public function update($id, CampaignDraft $campaignDraft) /** * Return the text and html contents of the campaigndraft - * * @param string $id - * * @return array + * @throws MailjetException */ - public function getDetailContent(string $id) + public function getDetailContent(string $id): array { $response = $this->mailjet->get(Resources::$CampaigndraftDetailcontent, ['id' => $id]); @@ -115,12 +114,12 @@ public function getDetailContent(string $id) /** * Creates the content of a campaigndraft - * * @param string $id - * + * @param array $contentData * @return array + * @throws MailjetException */ - public function createDetailContent($id, $contentData) + public function createDetailContent(string $id, array $contentData): array { $response = $this->mailjet->post(Resources::$CampaigndraftDetailcontent, ['id' => $id, 'body' => $contentData]); @@ -134,12 +133,11 @@ public function createDetailContent($id, $contentData) /** * Return the date of the scheduled sending of the campaigndraft - * - * @param string Campaign $id - * + * @param string $id * @return array + * @throws MailjetException */ - public function getSchedule(string $id) + public function getSchedule(string $id): array { $response = $this->mailjet->get(Resources::$CampaigndraftSchedule, ['id' => $id]); @@ -153,13 +151,12 @@ public function getSchedule(string $id) /** * Schedule when the campaigndraft will be sent - * * @param string $id * @param string $date (RFC3339 format "Y-m-d\TH:i:sP") - * * @return array + * @throws MailjetException */ - public function scheduleCampaign(string $id, string $date) + public function scheduleCampaign(string $id, string $date): array { $response = $this->mailjet->post(Resources::$CampaigndraftSchedule, ['id' => $id, 'body' => $date]); @@ -173,13 +170,12 @@ public function scheduleCampaign(string $id, string $date) /** * Update the date when the campaigndraft will be sent - * - * @param string Campaign $id - * @param string Schedule $date - * + * @param string $id + * @param string $date * @return array + * @throws MailjetException */ - public function updateCampaignSchedule($id, $date) + public function updateCampaignSchedule(string $id, string $date): array { $response = $this->mailjet->put(Resources::$CampaigndraftSchedule, ['id' => $id, 'body' => $date]); @@ -193,12 +189,11 @@ public function updateCampaignSchedule($id, $date) /** * Cancel a future sending - * - * @param string Campaign $id - * + * @param string $id * @return array + * @throws MailjetException */ - public function removeSchedule(string $id) + public function removeSchedule(string $id): array { $response = $this->mailjet->delete(Resources::$CampaigndraftSchedule, ['id' => $id]); @@ -212,12 +207,11 @@ public function removeSchedule(string $id) /** * Send the campaign immediately - * - * @param string Campaign $id - * + * @param string $id * @return array + * @throws MailjetException */ - public function sendCampaign(string $id) + public function sendCampaign(string $id): array { $response = $this->mailjet->post(Resources::$CampaigndraftSend, ['id' => $id]); @@ -231,12 +225,11 @@ public function sendCampaign(string $id) /** * Return the status of a CampaignDraft - * - * @param string Campaign $id - * + * @param string $id * @return array + * @throws MailjetException */ - public function getCampaignStatus(string $id) + public function getCampaignStatus(string $id): array { $response = $this->mailjet->get(Resources::$CampaigndraftStatus, ['id' => $id]); @@ -250,13 +243,12 @@ public function getCampaignStatus(string $id) /** * An action to test a CampaignDraft. - * - * @param string Campaign $id - * @param array of $recipients - * + * @param string $id + * @param array $recipients * @return array + * @throws MailjetException */ - public function testCampaign($id, $recipients) + public function testCampaign(string $id, array $recipients): array { $response = $this->mailjet->post(Resources::$CampaigndraftTest, ['id' => $id, 'body' => $recipients]); @@ -268,7 +260,12 @@ public function testCampaign($id, $recipients) return $response->getData(); } - private function throwError($title, Response $response) + /** + * @param $title + * @param Response $response + * @throws MailjetException + */ + private function throwError($title, Response $response): void { throw new MailjetException(0, $title, $response); } diff --git a/src/Services/CampaignService.php b/src/Services/CampaignService.php index c246b3c..0d421e0 100644 --- a/src/Services/CampaignService.php +++ b/src/Services/CampaignService.php @@ -26,9 +26,9 @@ public function __construct(MailjetService $mailjet) /** * List campaigns resources available for this apikey - * + * @param array|null $filters * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function getAllCampaigns(array $filters = null): array { @@ -43,11 +43,9 @@ public function getAllCampaigns(array $filters = null): array /** * Access a given campaign resource. - * * @param string $id - * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function findByCampaignId(string $id): array { @@ -66,7 +64,7 @@ public function findByCampaignId(string $id): array * @param string $id * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function findByNewsletterId(string $id): array { @@ -81,11 +79,10 @@ public function findByNewsletterId(string $id): array /** * Update one specific campaign resource with a PUT request. - * * @param string $id - * + * @param Campaign $campaign * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function updateCampaign(string $id, Campaign $campaign): array { From ddd733bf281a667257e92db69a9989dfd7677d1e Mon Sep 17 00:00:00 2001 From: Oleksandr Mykhailenko Date: Sun, 21 Jul 2024 20:24:15 +0300 Subject: [PATCH 2/2] Installed dependency for Symfony Http Client Added phpdocs for methods --- src/Contracts/ContactMetadataContract.php | 38 +++++++++--- src/Contracts/ContactsListContract.php | 46 +++++++++++++-- src/Contracts/ContactsV4Contract.php | 8 ++- src/Contracts/EventCallbackUrlContract.php | 20 +++++++ src/Contracts/MailjetServiceContract.php | 27 +++++++++ src/Contracts/TemplateServiceContract.php | 34 +++++++++++ src/Exception/MailjetException.php | 11 ++-- src/Facades/Mailjet.php | 3 + src/Services/ContactMetadataService.php | 24 +++----- src/Services/ContactsListService.php | 33 +++++------ src/Services/ContactsV4Service.php | 5 +- src/Services/EventCallbackUrlService.php | 13 ++-- src/Services/MailjetService.php | 69 ++++++++++------------ src/Services/TemplateService.php | 21 +++---- 14 files changed, 241 insertions(+), 111 deletions(-) diff --git a/src/Contracts/ContactMetadataContract.php b/src/Contracts/ContactMetadataContract.php index db1b31d..273f9ef 100644 --- a/src/Contracts/ContactMetadataContract.php +++ b/src/Contracts/ContactMetadataContract.php @@ -8,13 +8,33 @@ interface ContactMetadataContract { - public function getAll(); - - public function get(string $id); - - public function create(ContactMetadata $metadata); - - public function update(string $id, ContactMetadata $metadata); - - public function delete(string $id); + /** + * @return array + */ + public function getAll(): array; + + /** + * @param string $id + * @return array + */ + public function get(string $id): array; + + /** + * @param ContactMetadata $metadata + * @return array + */ + public function create(ContactMetadata $metadata): array; + + /** + * @param string $id + * @param ContactMetadata $metadata + * @return array + */ + public function update(string $id, ContactMetadata $metadata): array; + + /** + * @param string $id + * @return array + */ + public function delete(string $id): array; } diff --git a/src/Contracts/ContactsListContract.php b/src/Contracts/ContactsListContract.php index 5f4bb9e..e63cc10 100644 --- a/src/Contracts/ContactsListContract.php +++ b/src/Contracts/ContactsListContract.php @@ -9,17 +9,55 @@ interface ContactsListContract { - public function create(string $id, Contact $contact, $action = Contact::ACTION_ADDFORCE): array; - - public function update(string $id, Contact $contact, $action = Contact::ACTION_ADDNOFORCE): array; - + /** + * @param string $id + * @param Contact $contact + * @param string $action + * @return array + */ + public function create(string $id, Contact $contact, string $action = Contact::ACTION_ADDFORCE): array; + + /** + * @param string $id + * @param Contact $contact + * @param string $action + * @return array + */ + public function update(string $id, Contact $contact, string $action = Contact::ACTION_ADDNOFORCE): array; + + /** + * @param string $id + * @param Contact $contact + * @param bool $force + * @return array + */ public function subscribe(string $id, Contact $contact, bool $force = true): array; + /** + * @param string $id + * @param Contact $contact + * @return array + */ public function unsubscribe(string $id, Contact $contact): array; + /** + * @param string $id + * @param Contact $contact + * @return array + */ public function delete(string $id, Contact $contact): array; + /** + * @param string $id + * @param Contact $contact + * @param string $oldEmail + * @return array + */ public function updateEmail(string $id, Contact $contact, string $oldEmail): array; + /** + * @param ContactsList $list + * @return array + */ public function uploadManyContactsList(ContactsList $list): array; } diff --git a/src/Contracts/ContactsV4Contract.php b/src/Contracts/ContactsV4Contract.php index 9b1a351..d7c149a 100644 --- a/src/Contracts/ContactsV4Contract.php +++ b/src/Contracts/ContactsV4Contract.php @@ -9,5 +9,9 @@ interface ContactsV4Contract { - public function delete($id); -} \ No newline at end of file + /** + * @param int $id + * @return bool + */ + public function delete(int $id): bool; +} diff --git a/src/Contracts/EventCallbackUrlContract.php b/src/Contracts/EventCallbackUrlContract.php index 0e2ec90..eaecb5d 100644 --- a/src/Contracts/EventCallbackUrlContract.php +++ b/src/Contracts/EventCallbackUrlContract.php @@ -8,13 +8,33 @@ interface EventCallbackUrlContract { + /** + * @return array + */ public function getAll(): array; + /** + * @param string $id + * @return array + */ public function get(string $id): array; + /** + * @param EventCallbackUrl $url + * @return array + */ public function create(EventCallbackUrl $url): array; + /** + * @param string $id + * @param EventCallbackUrl $url + * @return array + */ public function update(string $id, EventCallbackUrl $url): array; + /** + * @param string $id + * @return array + */ public function delete(string $id): array; } diff --git a/src/Contracts/MailjetServiceContract.php b/src/Contracts/MailjetServiceContract.php index bc50558..cafe5bd 100644 --- a/src/Contracts/MailjetServiceContract.php +++ b/src/Contracts/MailjetServiceContract.php @@ -9,13 +9,40 @@ interface MailjetServiceContract { + /** + * @param array $resource + * @param array $args + * @param array $options + * @return Response + */ public function post(array $resource, array $args = [], array $options = []): Response; + /** + * @param array $resource + * @param array $args + * @param array $options + * @return Response + */ public function get(array $resource, array $args = [], array $options = []): Response; + /** + * @param array $resource + * @param array $args + * @param array $options + * @return Response + */ public function put(array $resource, array $args = [], array $options = []): Response; + /** + * @param array $resource + * @param array $args + * @param array $options + * @return Response + */ public function delete(array $resource, array $args = [], array $options = []): Response; + /** + * @return Client + */ public function getClient(): Client; } diff --git a/src/Contracts/TemplateServiceContract.php b/src/Contracts/TemplateServiceContract.php index ba7b1d8..995c962 100644 --- a/src/Contracts/TemplateServiceContract.php +++ b/src/Contracts/TemplateServiceContract.php @@ -8,19 +8,53 @@ interface TemplateServiceContract { + /** + * @param array|null $filters + * @return array + */ public function getAll(array $filters = null): array; + /** + * @param string $id + * @return array + */ public function get(string $id): array; + /** + * @param Template $template + * @return array + */ public function create(Template $template): array; + /** + * @param string $id + * @param Template $template + * @return array + */ public function update(string $id, Template $template): array; + /** + * @param string $id + * @return array + */ public function delete(string $id): array; + /** + * @param string $id + * @return array + */ public function getDetailContent(string $id): array; + /** + * @param string $id + * @param array $content + * @return array + */ public function createDetailContent(string $id, array $content): array; + /** + * @param string $id + * @return array + */ public function deleteDetailContent(string $id): array; } diff --git a/src/Exception/MailjetException.php b/src/Exception/MailjetException.php index 9421c5a..f77cf6e 100644 --- a/src/Exception/MailjetException.php +++ b/src/Exception/MailjetException.php @@ -26,14 +26,15 @@ class MailjetException extends \Exception /** * https://dev.mailjet.com/guides/#about-the-mailjet-restful-api - * - * @param Response $response - * @param \Throwable $previous + * @param int $statusCode + * @param null $message + * @param Response|null $response + * @param Throwable|null $previous */ - public function __construct($statusCode = 0, $message = null, Response $response = null, Throwable $previous = null) + public function __construct(int $statusCode = 0, $message = null, Response $response = null, Throwable $previous = null) { if ($response) { - $statusCode = $response->getStatus(); + $statusCode = $response->getStatus() ?? 0; $message = "{$message}: {$response->getReasonPhrase()}"; $this->setErrorFromResponse($response); diff --git a/src/Facades/Mailjet.php b/src/Facades/Mailjet.php index f2540e2..6502185 100644 --- a/src/Facades/Mailjet.php +++ b/src/Facades/Mailjet.php @@ -8,6 +8,9 @@ class Mailjet extends Facade { + /** + * @return string + */ protected static function getFacadeAccessor(): string { return 'Mailjet'; diff --git a/src/Services/ContactMetadataService.php b/src/Services/ContactMetadataService.php index 42415c3..47f3a35 100644 --- a/src/Services/ContactMetadataService.php +++ b/src/Services/ContactMetadataService.php @@ -26,9 +26,8 @@ public function __construct(MailjetService $mailjet) /** * Retrieve all ContactMetadata. - * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function getAll(): array { @@ -43,11 +42,9 @@ public function getAll(): array /** * Retrieve one ContactMetadata. - * * @param string $id - * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function get(string $id): array { @@ -62,10 +59,9 @@ public function get(string $id): array /** * create a new fresh ContactMetadata - * * @param ContactMetadata $metadata - * - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return array + * @throws MailjetException */ public function create(ContactMetadata $metadata): array { @@ -80,11 +76,10 @@ public function create(ContactMetadata $metadata): array /** * Update one ContactMetadata - * - * @param string $id + * @param string $id * @param ContactMetadata $metadata - * - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return array + * @throws MailjetException */ public function update(string $id, ContactMetadata $metadata): array { @@ -99,10 +94,9 @@ public function update(string $id, ContactMetadata $metadata): array /** * Delete one ContactMetadata - * * @param string $id - * - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return array + * @throws MailjetException */ public function delete(string $id): array { diff --git a/src/Services/ContactsListService.php b/src/Services/ContactsListService.php index 1630dec..e66b4df 100644 --- a/src/Services/ContactsListService.php +++ b/src/Services/ContactsListService.php @@ -33,15 +33,13 @@ public function __construct(MailjetService $mailjet) /** * Create a new fresh Contact to listId. - * * @param string $id * @param Contact $contact - * @param string $action - * + * @param string $action * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ - public function create(string $id, Contact $contact, $action = Contact::ACTION_ADDFORCE): array + public function create(string $id, Contact $contact, string $action = Contact::ACTION_ADDFORCE): array { $contact->setAction($action); @@ -56,15 +54,13 @@ public function create(string $id, Contact $contact, $action = Contact::ACTION_A /** * Update a Contact to listId. - * * @param string $id * @param Contact $contact - * @param string $action - * + * @param string $action * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ - public function update(string $id, Contact $contact, $action = Contact::ACTION_ADDNOFORCE): array + public function update(string $id, Contact $contact, string $action = Contact::ACTION_ADDNOFORCE): array { $contact->setAction($action); @@ -85,7 +81,7 @@ public function update(string $id, Contact $contact, $action = Contact::ACTION_A * @param bool $force * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function subscribe(string $id, Contact $contact, bool $force = true): array { @@ -107,7 +103,7 @@ public function subscribe(string $id, Contact $contact, bool $force = true): arr * @param Contact $contact * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function unsubscribe(string $id, Contact $contact): array { @@ -129,7 +125,7 @@ public function unsubscribe(string $id, Contact $contact): array * @param Contact $contact * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function delete(string $id, Contact $contact): array { @@ -152,7 +148,7 @@ public function delete(string $id, Contact $contact): array * @param string $oldEmail * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function updateEmail(string $id, Contact $contact, string $oldEmail): array { @@ -193,7 +189,7 @@ public function updateEmail(string $id, Contact $contact, string $oldEmail): arr * @param ContactsList $list * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function uploadManyContactsList(ContactsList $list): array { @@ -226,11 +222,10 @@ public function uploadManyContactsList(ContactsList $list): array * or updates the entry with these values. * On success, the API returns a packet with the same format * but with all properties available for that contact. - * - * @param string $id + * @param string $id * @param Contact $contact - * - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return Response + * @throws MailjetException */ private function _exec(string $id, Contact $contact): Response { diff --git a/src/Services/ContactsV4Service.php b/src/Services/ContactsV4Service.php index 709bfcf..367a2f9 100644 --- a/src/Services/ContactsV4Service.php +++ b/src/Services/ContactsV4Service.php @@ -29,8 +29,9 @@ public function __construct(MailjetService $mailjet) * Delete a Contact * @param int $id * @return bool + * @throws MailjetException */ - public function delete($id) + public function delete(int $id): bool { $response = $this->mailjet->delete(['contacts', ''], ['id' => $id]); @@ -40,4 +41,4 @@ public function delete($id) return 200 === $response->getStatus(); } -} \ No newline at end of file +} diff --git a/src/Services/EventCallbackUrlService.php b/src/Services/EventCallbackUrlService.php index b03c76b..c08d727 100644 --- a/src/Services/EventCallbackUrlService.php +++ b/src/Services/EventCallbackUrlService.php @@ -26,9 +26,8 @@ public function __construct(MailjetService $mailjet) /** * Retrieve all EventCallbackUrl. - * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function getAll(): array { @@ -43,11 +42,9 @@ public function getAll(): array /** * Retrieve one EventCallbackUrl. - * * @param string $id - * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function get(string $id): array { @@ -66,7 +63,7 @@ public function get(string $id): array * @param EventCallbackUrl $url * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function create(EventCallbackUrl $url): array { @@ -86,7 +83,7 @@ public function create(EventCallbackUrl $url): array * @param EventCallbackUrl $url * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function update(string $id, EventCallbackUrl $url): array { @@ -105,7 +102,7 @@ public function update(string $id, EventCallbackUrl $url): array * @param string $id * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function delete(string $id): array { diff --git a/src/Services/MailjetService.php b/src/Services/MailjetService.php index 1420ebb..5e4b0db 100644 --- a/src/Services/MailjetService.php +++ b/src/Services/MailjetService.php @@ -13,24 +13,28 @@ class MailjetService implements MailjetServiceContract { /** - * @var \Mailjet\Client + * @var Client */ private $client; - public function __construct(string $key, string $secret, $call = true, array $settings = []) + /** + * @param string $key + * @param string $secret + * @param bool $call + * @param array $settings + */ + public function __construct(string $key, string $secret, bool $call = true, array $settings = []) { $this->client = new Client($key, $secret, $call, $settings); } /** * Trigger a POST request. - * * @param array $resource Mailjet Resource/Action pair * @param array $args Request arguments * @param array $options - * * @return Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function post(array $resource, array $args = [], array $options = []): Response { @@ -51,7 +55,7 @@ public function post(array $resource, array $args = [], array $options = []): Re * @param array $options * * @return Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function get(array $resource, array $args = [], array $options = []): Response { @@ -72,7 +76,7 @@ public function get(array $resource, array $args = [], array $options = []): Res * @param array $options * * @return Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function put(array $resource, array $args = [], array $options = []): Response { @@ -93,7 +97,7 @@ public function put(array $resource, array $args = [], array $options = []): Res * @param array $options * * @return Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function delete(array $resource, array $args = [], array $options = []): Response { @@ -109,13 +113,11 @@ public function delete(array $resource, array $args = [], array $options = []): /** * Get all list on your Mailjet account. * TODO: Exclude HIGH Level API methods into managers. - * - * @param array $filters Filters that will be use to filter the request - * - * @return \Mailjet\Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @param array|null $filters Filters that will be use to filter the request + * @return Response + * @throws MailjetException */ - public function getAllLists(array $filters = null): Response + public function getAllLists(?array $filters = null): Response { $response = $this->client->get(Resources::$Contactslist, ['filters' => $filters]); @@ -128,11 +130,9 @@ public function getAllLists(array $filters = null): Response /** * Create a new list. - * * @param array $body Information list - the 'Name' field is mandatory. - * - * @return \Mailjet\Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return Response + * @throws MailjetException */ public function createList(array $body): Response { @@ -147,13 +147,11 @@ public function createList(array $body): Response /** * Get all list recipient on your Mailjet account. - * - * @param array $filters Filters that will be use to filter the request. - * - * @return \Mailjet\Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @param array|null $filters Filters that will be use to filter the request. + * @return Response + * @throws MailjetException */ - public function getListRecipients(array $filters = null): Response + public function getListRecipients(?array $filters = null): Response { $response = $this->client->get(Resources::$Listrecipient, ['filters' => $filters]); @@ -166,11 +164,9 @@ public function getListRecipients(array $filters = null): Response /** * Get single contact information. - * * @param string $id - * - * @return \Mailjet\Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return Response + * @throws MailjetException */ public function getSingleContact(string $id): Response { @@ -188,14 +184,14 @@ public function getSingleContact(string $id): Response * * @param array $body Information list - the 'Email' field is mandatory. * - * @return \Mailjet\Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return Response + * @throws MailjetException */ public function createContact(array $body): Response { $response = $this->client->post(Resources::$Contact, ['body' => $body]); - if (! $response->success()) { + if (!$response->success()) { throw new MailjetException(0, 'MailjetService:createContact() failed', $response); } @@ -207,8 +203,8 @@ public function createContact(array $body): Response * * @param array $body Information list - the 'ContactID' and 'ListID' parameters are mandatory. * - * @return \Mailjet\Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return Response + * @throws MailjetException */ public function createListRecipient(array $body): Response { @@ -227,8 +223,8 @@ public function createListRecipient(array $body): Response * @param string $id * @param array $body Information list - the 'ContactID' and 'ListID' parameters are mandatory. * - * @return \Mailjet\Response - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @return Response + * @throws MailjetException */ public function editListRecipient(string $id, array $body): Response { @@ -243,8 +239,7 @@ public function editListRecipient(string $id, array $body): Response /** * Retrieve Mailjet client. - * - * @return \Mailjet\Client + * @return Client */ public function getClient(): Client { diff --git a/src/Services/TemplateService.php b/src/Services/TemplateService.php index 183142a..bb738b8 100644 --- a/src/Services/TemplateService.php +++ b/src/Services/TemplateService.php @@ -19,6 +19,9 @@ class TemplateService implements TemplateServiceContract */ protected $mailjet; + /** + * @param MailjetService $mailjet + */ public function __construct(MailjetService $mailjet) { $this->mailjet = $mailjet; @@ -27,11 +30,9 @@ public function __construct(MailjetService $mailjet) /** * List template resources available for this apikey, use a GET request. * Alternatively, you may want to add one or more filters. - * * @param array|null $filters - * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function getAll(array $filters = null): array { @@ -50,7 +51,7 @@ public function getAll(array $filters = null): array * @param string $id * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function get(string $id): array { @@ -69,7 +70,7 @@ public function get(string $id): array * @param Template $template * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function create(Template $template): array { @@ -89,7 +90,7 @@ public function create(Template $template): array * @param Template $template * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function update(string $id, Template $template): array { @@ -108,7 +109,7 @@ public function update(string $id, Template $template): array * @param string $id * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function delete(string $id): array { @@ -127,7 +128,7 @@ public function delete(string $id): array * @param string $id * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function getDetailContent(string $id): array { @@ -147,7 +148,7 @@ public function getDetailContent(string $id): array * @param array $content * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function createDetailContent(string $id, array $content): array { @@ -166,7 +167,7 @@ public function createDetailContent(string $id, array $content): array * @param string $id * * @return array - * @throws \Mailjet\LaravelMailjet\Exception\MailjetException + * @throws MailjetException */ public function deleteDetailContent(string $id): array {