Skip to content

Commit

Permalink
Php code sniffer changes (#868)
Browse files Browse the repository at this point in the history
* Php code sniffer changes

* For `bold` operations we should close resource even if it fails

* cs

* composer normalize
  • Loading branch information
oleksandr-mykhailenko authored Aug 13, 2023
1 parent 181749e commit 02d8b5c
Show file tree
Hide file tree
Showing 73 changed files with 444 additions and 223 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"nyholm/nsa": "^1.2.1",
"nyholm/psr7": "^1.3.1",
"phpunit/phpunit": "^9.3",
"squizlabs/php_codesniffer": "^3.7",
"symfony/http-client": "^5.3"
},
"suggest": {
Expand All @@ -36,6 +37,11 @@
"Mailgun\\Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"php-http/discovery": true
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
Expand Down
9 changes: 6 additions & 3 deletions src/Api/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use Psr\Http\Message\ResponseInterface;

/**
* @see https://documentation.mailgun.com/api-domains.html
* @see https://documentation.mailgun.com/api-domains.html
*
* @author Sean Johnson <[email protected]>
*/
Expand All @@ -43,6 +43,7 @@ class Domain extends HttpApi

/**
* Returns a list of domains on the account.
*
* @param int $limit
* @param int $skip
* @return IndexResponse|array
Expand Down Expand Up @@ -84,7 +85,8 @@ public function show(string $domain)
* Creates a new domain for the account.
* See below for spam filtering parameter information.
* {@link https://documentation.mailgun.com/user_manual.html#um-spam-filter}.
* @see https://documentation.mailgun.com/en/latest/api-domains.html#domains
*
* @see https://documentation.mailgun.com/en/latest/api-domains.html#domains
* @param string $domain name of the domain
* @param string|null $smtpPass password for SMTP authentication
* @param string|null $spamAction `disable` or `tag` - inbound spam filtering
Expand All @@ -93,7 +95,8 @@ public function show(string $domain)
* @param string[] $ips an array of ips to be assigned to the domain
* @param ?string $pool_id pool id to assign to the domain
* @param string $webScheme `http` or `https` - set your open, click and unsubscribe URLs to use http or https. The default is http
* @param string $dkimKeySize Set length of your domain’s generated DKIM key
* @param string $dkimKeySize Set length of your domain’s generated DKIM
* key
* @return CreateResponse|array|ResponseInterface
* @throws Exception
*/
Expand Down
1 change: 1 addition & 0 deletions src/Api/EmailValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EmailValidation extends HttpApi
/**
* Addresses are validated based off defined checks.
* This operation is only accessible with the private API key and not subject to the daily usage limits.
*
* @param string $address An email address to validate. Maximum: 512 characters.
* @param bool $mailboxVerification If set to true, a mailbox verification check will be performed
* against the address. The default is False.
Expand Down
35 changes: 26 additions & 9 deletions src/Api/EmailValidationV4.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Mailgun\Model\EmailValidationV4\ValidateResponse;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use RuntimeException;

/**
* @see https://documentation.mailgun.com/en/latest/api-email-validation.html
Expand All @@ -32,8 +33,10 @@ class EmailValidationV4 extends HttpApi
{
/**
* Addresses are validated based off defined checks.
*
* @param string $address An email address to validate. Maximum: 512 characters.
* @param bool $providerLookup A provider lookup will be performed if Mailgun’s internal analysis is insufficient
* @param bool $providerLookup A provider lookup will be performed if Mailgun’s internal analysis is
* insufficient
* @return ValidateResponse|ResponseInterface
* @throws Exception|ClientExceptionInterface Thrown when we don't catch a Client or Server side Exception
*/
Expand Down Expand Up @@ -73,8 +76,13 @@ public function createBulkJob(string $listId, $filePath)
$postDataMultipart = [];
$postDataMultipart[] = $this->prepareFile('file', $fileData);

$response = $this->httpPostRaw(sprintf('/v4/address/validate/bulk/%s', $listId), $postDataMultipart);
$this->closeResources($postDataMultipart);
try {
$response = $this->httpPostRaw(sprintf('/v4/address/validate/bulk/%s', $listId), $postDataMultipart);
} catch (Exception $exception) {
throw new RuntimeException($exception->getMessage());
} finally {
$this->closeResources($postDataMultipart);
}

return $this->hydrateResponse($response, CreateBulkJobResponse::class);
}
Expand Down Expand Up @@ -118,9 +126,11 @@ public function getBulkJobs(int $limit = 500)
{
Assert::greaterThan($limit, 0);

$response = $this->httpGet('/v4/address/validate/bulk', [
$response = $this->httpGet(
'/v4/address/validate/bulk', [
'limit' => $limit,
]);
]
);

return $this->hydrateResponse($response, GetBulkJobsResponse::class);
}
Expand All @@ -134,9 +144,11 @@ public function getBulkPreviews(int $limit = 500)
{
Assert::greaterThan($limit, 0);

$response = $this->httpGet('/v4/address/validate/preview', [
$response = $this->httpGet(
'/v4/address/validate/preview', [
'limit' => $limit,
]);
]
);

return $this->hydrateResponse($response, GetBulkPreviewsResponse::class);
}
Expand All @@ -163,8 +175,13 @@ public function createBulkPreview(string $previewId, $filePath)
$postDataMultipart = [];
$postDataMultipart[] = $this->prepareFile('file', $fileData);

$response = $this->httpPostRaw(sprintf('/v4/address/validate/preview/%s', $previewId), $postDataMultipart);
$this->closeResources($postDataMultipart);
try {
$response = $this->httpPostRaw(sprintf('/v4/address/validate/preview/%s', $previewId), $postDataMultipart);
} catch (Exception $exception) {
throw new RuntimeException($exception->getMessage());
} finally {
$this->closeResources($postDataMultipart);
}

return $this->hydrateResponse($response, CreateBulkPreviewResponse::class);
}
Expand Down
1 change: 1 addition & 0 deletions src/Api/HttpApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ protected function httpGet(string $path, array $parameters = [], array $requestH

/**
* Send a POST request with parameters.
*
* @param string $path Request path
* @param array $parameters POST parameters
* @param array $requestHeaders Request headers
Expand Down
2 changes: 1 addition & 1 deletion src/Api/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Psr\Http\Message\ResponseInterface;

/**
* @see https://documentation.mailgun.com/api-domains.html
* @see https://documentation.mailgun.com/api-domains.html
*
* @author Sean Johnson <[email protected]>
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Api/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Ip extends HttpApi
{
/**
* Returns a list of IPs.
*
* @return IndexResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -45,6 +46,7 @@ public function index(?bool $dedicated = null)

/**
* Returns a list of IPs assigned to a domain.
*
* @return IndexResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -59,6 +61,7 @@ public function domainIndex(string $domain)

/**
* Returns a single ip.
*
* @return ShowResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -73,6 +76,7 @@ public function show(string $ip)

/**
* Assign a dedicated IP to the domain specified.
*
* @return UpdateResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -92,6 +96,7 @@ public function assign(string $domain, string $ip)

/**
* Unassign an IP from the domain specified.
*
* @return UpdateResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Api/MailingList.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function member(): Member

/**
* Returns a paginated list of mailing lists on the domain.
*
* @param int $limit Maximum number of records to return (optional: 100 by default)
* @return PagesResponse
* @throws Exception|ClientExceptionInterface
Expand All @@ -58,6 +59,7 @@ public function pages(int $limit = 100)

/**
* Creates a new mailing list on the current domain.
*
* @param string $address Address for the new mailing list
* @param string|null $name Name for the new mailing list (optional)
* @param string|null $description Description for the new mailing list (optional)
Expand Down Expand Up @@ -89,6 +91,7 @@ public function create(string $address, ?string $name = null, ?string $descripti

/**
* Returns a single mailing list.
*
* @param string $address Address of the mailing list
* @return ShowResponse
* @throws Exception|ClientExceptionInterface
Expand All @@ -104,6 +107,7 @@ public function show(string $address)

/**
* Updates a mailing list.
*
* @param string $address Address of the mailing list
* @param array $parameters Array of field => value pairs to update
* @return UpdateResponse
Expand Down Expand Up @@ -136,6 +140,7 @@ public function update(string $address, array $parameters = [])

/**
* Removes a mailing list from the domain.
*
* @param string $address Address of the mailing list
* @return DeleteResponse
* @throws Exception|ClientExceptionInterface
Expand All @@ -151,6 +156,7 @@ public function delete(string $address)

/**
* Validates mailing list.
*
* @param string $address Address of the mailing list
* @return ValidateResponse
* @throws Exception|ClientExceptionInterface
Expand All @@ -166,6 +172,7 @@ public function validate(string $address)

/**
* Get mailing list validation status.
*
* @param string $address Address of the mailing list
* @return ValidationStatusResponse
* @throws Exception|ClientExceptionInterface
Expand All @@ -181,6 +188,7 @@ public function getValidationStatus(string $address)

/**
* Cancel mailing list validation.
*
* @param string $address Address of the mailing list
* @return ValidationCancelResponse
* @throws Exception|ClientExceptionInterface
Expand Down
1 change: 1 addition & 0 deletions src/Api/MailingList/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function show(string $list, string $address)

/**
* Creates (or updates) a member of the mailing list.
*
* @param string $list Address of the mailing list
* @param string $address Address for the member
* @param string|null $name Name for the member (optional)
Expand Down
19 changes: 15 additions & 4 deletions src/Api/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Mailgun\Model\Message\ShowResponse;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use RuntimeException;

/**
* @see https://documentation.mailgun.com/en/latest/api-sending.html
Expand Down Expand Up @@ -65,8 +66,13 @@ public function send(string $domain, array $params)
}

$postDataMultipart = array_merge($this->prepareMultipartParameters($params), $postDataMultipart);
$response = $this->httpPostRaw(sprintf('/v3/%s/messages', $domain), $postDataMultipart);
$this->closeResources($postDataMultipart);
try {
$response = $this->httpPostRaw(sprintf('/v3/%s/messages', $domain), $postDataMultipart);
} catch (Exception $exception) {
throw new RuntimeException($exception->getMessage());
} finally {
$this->closeResources($postDataMultipart);
}

return $this->hydrateResponse($response, SendResponse::class);
}
Expand Down Expand Up @@ -101,8 +107,13 @@ public function sendMime(string $domain, array $recipients, string $message, arr
];
}
$postDataMultipart[] = $this->prepareFile('message', $fileData);
$response = $this->httpPostRaw(sprintf('/v3/%s/messages.mime', $domain), $postDataMultipart);
$this->closeResources($postDataMultipart);
try {
$response = $this->httpPostRaw(sprintf('/v3/%s/messages.mime', $domain), $postDataMultipart);
} catch (Exception $exception) {
throw new RuntimeException($exception->getMessage());
} finally {
$this->closeResources($postDataMultipart);
}

return $this->hydrateResponse($response, SendResponse::class);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Api/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Route extends HttpApi
{
/**
* Fetches the list of Routes.
*
* @param int $limit Maximum number of records to return. (100 by default)
* @param int $skip Number of records to skip. (0 by default)
* @return IndexResponse
Expand All @@ -51,6 +52,7 @@ public function index(int $limit = 100, int $skip = 0)

/**
* Returns a single Route object based on its ID.
*
* @param string $routeId Route ID returned by the Routes::index() method
* @return ShowResponse
* @throws ClientExceptionInterface
Expand All @@ -66,6 +68,7 @@ public function show(string $routeId)

/**
* Creates a new Route.
*
* @param string $expression A filter expression like "match_recipient('.*@gmail.com')"
* @param array $actions Route action. This action is executed when the expression evaluates to True. Example: "forward('[email protected]')"
* @param string $description An arbitrary string
Expand All @@ -92,6 +95,7 @@ public function create(string $expression, array $actions, string $description,
/**
* Updates a given Route by ID. All parameters are optional.
* This API call only updates the specified fields leaving others unchanged.
*
* @param string $routeId Route ID returned by the Routes::index() method
* @param string|null $expression A filter expression like "match_recipient('.*@gmail.com')"
* @param array $actions Route action. This action is executed when the expression evaluates to True. Example: "forward('[email protected]')"
Expand Down Expand Up @@ -136,6 +140,7 @@ public function update(

/**
* Deletes a Route based on the ID.
*
* @param string $routeId Route ID returned by the Routes::index() method
* @return DeleteResponse
* @throws ClientExceptionInterface
Expand Down
5 changes: 5 additions & 0 deletions src/Api/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Tag extends HttpApi

/**
* Returns a list of tags.
*
* @return IndexResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -53,6 +54,7 @@ public function index(string $domain, int $limit = 100)

/**
* Returns a single tag.
*
* @return ShowResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -68,6 +70,7 @@ public function show(string $domain, string $tag)

/**
* Update a tag.
*
* @return UpdateResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -87,6 +90,7 @@ public function update(string $domain, string $tag, string $description)

/**
* Returns statistics for a single tag.
*
* @return StatisticsResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand All @@ -102,6 +106,7 @@ public function stats(string $domain, string $tag, array $params)

/**
* Removes a tag from the account.
*
* @return DeleteResponse|ResponseInterface
* @throws ClientExceptionInterface
*/
Expand Down
Loading

0 comments on commit 02d8b5c

Please sign in to comment.