Skip to content

Commit 3a0d6b9

Browse files
Merge pull request #11 from Rutam21/APPW-4358
Issue-4358: Add Code Linter To utopia-php/messaging
2 parents 887590e + 8387f7f commit 3a0d6b9

20 files changed

Lines changed: 179 additions & 150 deletions

File tree

.github/workflows/linter.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ jobs:
1111
uses: actions/checkout@v3
1212
with:
1313
fetch-depth: 2
14+
1415
- run: git checkout HEAD^2
16+
1517
- name: Run Linter
1618
run: |
1719
docker run --rm -v $PWD:/app composer sh -c \

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"minimum-stability": "stable",
88
"scripts": {
99
"test": "vendor/bin/phpunit",
10-
"lint": "vendor/bin/phpcs",
11-
"format": "vendor/bin/phpcbf"
10+
"lint": "./vendor/bin/pint --test",
11+
"format": "./vendor/bin/pint"
1212
},
1313
"autoload": {
1414
"psr-4": {
@@ -28,7 +28,7 @@
2828
"require-dev": {
2929
"phpunit/phpunit": "9.5.*",
3030
"phpmailer/phpmailer": "6.6.*",
31-
"squizlabs/php_codesniffer": "^3.6"
31+
"laravel/pint": "^1.2"
3232
},
3333
"config": {
3434
"platform": {

composer.lock

Lines changed: 67 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Utopia/Messaging/Adapter.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,20 @@ abstract public function getMaxMessagesPerRequest(): int;
3535
/**
3636
* Send a message.
3737
*
38-
* @param Message $message The message to send.
38+
* @param Message $message The message to send.
3939
* @return string The response body.
4040
*/
4141
abstract public function send(Message $message): string;
4242

4343
/**
4444
* Send an HTTP request.
4545
*
46-
* @param string $method The HTTP method to use.
47-
* @param string $url The URL to send the request to.
48-
* @param array $headers An array of headers to send with the request.
49-
* @param string|null $body The body of the request.
46+
* @param string $method The HTTP method to use.
47+
* @param string $url The URL to send the request to.
48+
* @param array $headers An array of headers to send with the request.
49+
* @param string|null $body The body of the request.
5050
* @return string The response body.
51+
*
5152
* @throws \Exception If the request fails.
5253
*/
5354
protected function request(
@@ -56,7 +57,7 @@ protected function request(
5657
array $headers = [],
5758
mixed $body = null,
5859
): string {
59-
$headers[] = 'Content-length: ' . \strlen($body);
60+
$headers[] = 'Content-length: '.\strlen($body);
6061

6162
$ch = \curl_init();
6263

@@ -66,14 +67,14 @@ protected function request(
6667
\curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
6768
\curl_setopt($ch, CURLOPT_USERAGENT, "Appwrite {$this->getName()} Message Sender");
6869

69-
if (!is_null($body)) {
70+
if (! is_null($body)) {
7071
\curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
7172
}
7273

7374
$response = \curl_exec($ch);
7475

7576
if (\curl_errno($ch)) {
76-
throw new \Exception('Error:' . \curl_error($ch));
77+
throw new \Exception('Error:'.\curl_error($ch));
7778
}
7879
if (\curl_getinfo($ch, CURLINFO_HTTP_CODE) >= 400) {
7980
throw new \Exception($response);

src/Utopia/Messaging/Adapters/Email.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@ public function getMessageType(): string
1919
}
2020

2121
/**
22-
* @inheritdoc
22+
* {@inheritdoc}
23+
*
2324
* @throws \Exception
2425
*/
2526
public function send(Message $message): string
2627
{
27-
if (!\is_a($message, $this->getMessageType())) {
28+
if (! \is_a($message, $this->getMessageType())) {
2829
throw new \Exception('Invalid message type.');
2930
}
3031
if (\count($message->getTo()) > $this->getMaxMessagesPerRequest()) {
3132
throw new \Exception("{$this->getName()} can only send {$this->getMaxMessagesPerRequest()} messages per request.");
3233
}
34+
3335
return $this->process($message);
3436
}
3537

3638
/**
3739
* Process an email message.
3840
*
39-
* @param EmailMessage $message Message to process.
41+
* @param EmailMessage $message Message to process.
4042
* @return string The response body.
4143
*/
4244
abstract protected function process(EmailMessage $message): string;

src/Utopia/Messaging/Adapters/Email/Mailgun.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace Utopia\Messaging\Adapters\Email;
44

5-
use Utopia\Messaging\Messages\Email;
65
use Utopia\Messaging\Adapters\Email as EmailAdapter;
6+
use Utopia\Messaging\Messages\Email;
77

88
class Mailgun extends EmailAdapter
99
{
1010
/**
11-
* @param string $apiKey Your Mailgun API key to authenticate with the API.
12-
* @param string $domain Your Mailgun domain to send messages from.
11+
* @param string $apiKey Your Mailgun API key to authenticate with the API.
12+
* @param string $domain Your Mailgun domain to send messages from.
1313
*/
1414
public function __construct(
1515
private string $apiKey,
@@ -28,7 +28,8 @@ public function getMaxMessagesPerRequest(): int
2828
}
2929

3030
/**
31-
* @inheritdoc
31+
* {@inheritdoc}
32+
*
3233
* @throws \Exception
3334
*/
3435
protected function process(Email $message): string
@@ -37,7 +38,7 @@ protected function process(Email $message): string
3738
method: 'POST',
3839
url: "https://api.mailgun.net/v3/{$this->domain}/messages",
3940
headers: [
40-
'Authorization: Basic ' . base64_encode('api:' . $this->apiKey)
41+
'Authorization: Basic '.base64_encode('api:'.$this->apiKey),
4142
],
4243
body: [
4344
'from' => $message->getFrom(),

src/Utopia/Messaging/Adapters/Email/Mock.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use PHPMailer\PHPMailer\Exception;
66
use PHPMailer\PHPMailer\PHPMailer;
7-
use Utopia\Messaging\Messages\Email;
87
use Utopia\Messaging\Adapters\Email as EmailAdapter;
8+
use Utopia\Messaging\Messages\Email;
99

1010
class Mock extends EmailAdapter
1111
{
@@ -21,7 +21,8 @@ public function getMaxMessagesPerRequest(): int
2121
}
2222

2323
/**
24-
* @inheritdoc
24+
* {@inheritdoc}
25+
*
2526
* @throws Exception
2627
* @throws \Exception
2728
*/
@@ -49,7 +50,7 @@ protected function process(Email $message): string
4950
$mail->addAddress($to);
5051
}
5152

52-
if (!$mail->send()) {
53+
if (! $mail->send()) {
5354
throw new \Exception($mail->ErrorInfo);
5455
}
5556

src/Utopia/Messaging/Adapters/Email/Sendgrid.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Utopia\Messaging\Adapters\Email;
44

5-
use Utopia\Messaging\Messages\Email;
65
use Utopia\Messaging\Adapters\Email as EmailAdapter;
6+
use Utopia\Messaging\Messages\Email;
77

88
class Sendgrid extends EmailAdapter
99
{
@@ -28,14 +28,14 @@ protected function process(Email $message): string
2828
method: 'POST',
2929
url: 'https://api.sendgrid.com/v3/mail/send',
3030
headers: [
31-
'Authorization: Bearer ' . $this->apiKey,
31+
'Authorization: Bearer '.$this->apiKey,
3232
'Content-Type: application/json',
3333
],
3434
body: \json_encode([
3535
'personalizations' => [
3636
[
3737
'to' => \array_map(
38-
fn($to) => ['email' => $to],
38+
fn ($to) => ['email' => $to],
3939
$message->getTo()
4040
),
4141
'subject' => $message->getSubject(),

src/Utopia/Messaging/Adapters/Push.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@ public function getMessageType(): string
1919
}
2020

2121
/**
22-
* @inheritdoc
22+
* {@inheritdoc}
23+
*
2324
* @throws \Exception
2425
*/
2526
public function send(Message $message): string
2627
{
27-
if (!\is_a($message, $this->getMessageType())) {
28+
if (! \is_a($message, $this->getMessageType())) {
2829
throw new \Exception('Invalid message type.');
2930
}
3031
if (\count($message->getTo()) > $this->getMaxMessagesPerRequest()) {
3132
throw new \Exception("{$this->getName()} can only send {$this->getMaxMessagesPerRequest()} messages per request.");
3233
}
34+
3335
return $this->process($message);
3436
}
3537

3638
/**
3739
* Send a push message.
3840
*
39-
* @param PushMessage $message Message to process.
41+
* @param PushMessage $message Message to process.
4042
* @return string The response body.
4143
*/
4244
abstract protected function process(PushMessage $message): string;

0 commit comments

Comments
 (0)