Skip to content

Commit 3a14bf3

Browse files
committed
Fix code style for PSR12
1 parent cfdd568 commit 3a14bf3

13 files changed

+147
-54
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
},
1919
"require-dev": {
2020
"phpunit/phpunit": "^4.8.35 || ^5.7",
21-
"fzaninotto/faker": "~1.8"
21+
"fzaninotto/faker": "~1.8",
22+
"squizlabs/php_codesniffer": "^3.5"
2223
},
2324
"suggest": {
2425
"ext-fileinfo": "Mime-Type detecting"

composer.lock

+52-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Exception/RecipientsListEmptyException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use Exception;
66
use Throwable;
77

8-
class RecipientsListEmptyException extends Exception
8+
final class RecipientsListEmptyException extends Exception
99
{
1010

1111
public function __construct(Throwable $previous = null)
1212
{
1313
parent::__construct("recipients list is empty", 1, $previous);
1414
}
15-
}
15+
}

src/Mailer.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ public function personal(Message $message, $priority = 0)
6363
*/
6464
private function sendMail(Message $message, $personal = false, $priority = 1)
6565
{
66-
if ($this->from) $message->setHeader("From", $this->from);
66+
if ($this->from) {
67+
$message->setHeader("From", $this->from);
68+
}
6769
$priority = (int)$priority;
6870
$params = array();
69-
if ($priority < 1) $priority = 0;
71+
if ($priority < 1) {
72+
$priority = 0;
73+
}
7074
if ($priority) {
7175
$fn = array($this->spool, "add");
7276
$params[1] = $priority;
@@ -79,8 +83,9 @@ private function sendMail(Message $message, $personal = false, $priority = 1)
7983
ksort($params);
8084
try {
8185
call_user_func_array($fn, $params);
82-
} catch (Throwable $e) {}
86+
} catch (Throwable $e) {
87+
}
8388
}
8489
return $this;
8590
}
86-
}
91+
}

src/Message.php

+43-19
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ public function addTo($email, $name = "")
9797

9898
public function removeTo($email)
9999
{
100-
if (array_key_exists($email, $this->to)) unset($this->to[$email]);
100+
if (array_key_exists($email, $this->to)) {
101+
unset($this->to[$email]);
102+
}
101103
$this->replaceHeaderTo();
102104
return $this;
103105
}
@@ -116,7 +118,9 @@ public function addCc($email, $name = "")
116118

117119
public function removeCc($email)
118120
{
119-
if (array_key_exists($email, $this->cc)) unset($this->cc[$email]);
121+
if (array_key_exists($email, $this->cc)) {
122+
unset($this->cc[$email]);
123+
}
120124
$this->replaceHeaderCc();
121125
return $this;
122126
}
@@ -135,7 +139,9 @@ public function addBcc($email, $name = "")
135139

136140
public function removeBcc($email)
137141
{
138-
if (array_key_exists($email, $this->bcc)) unset($this->bcc[$email]);
142+
if (array_key_exists($email, $this->bcc)) {
143+
unset($this->bcc[$email]);
144+
}
139145
$this->replaceHeaderBcc();
140146
return $this;
141147
}
@@ -148,8 +154,12 @@ public function getBcc()
148154
public function setFrom($email, $name = "")
149155
{
150156
$email = (string)$email;
151-
if (!$email) return $this;
152-
if (!$this->checkEmail($email)) return $this;
157+
if (!$email) {
158+
return $this;
159+
}
160+
if (!$this->checkEmail($email)) {
161+
return $this;
162+
}
153163
$contact = $this->getContact($email, $name);
154164
$this->setHeaderRaw("From", $contact);
155165
return $this;
@@ -269,7 +279,7 @@ private function createBodyMessagePlainPart($content)
269279
{
270280
$text = "\r\nContent-type: text/plain; charset=UTF-8\r\n";
271281
$text .= "Content-Transfer-Encoding: base64\r\n\r\n";
272-
$text .= chunk_split($content)."\r\n";
282+
$text .= chunk_split($content) . "\r\n";
273283
return $text;
274284
}
275285

@@ -282,7 +292,7 @@ private function createBodyMessageHtmlPart($content)
282292

283293
$part = "\r\nContent-type: text/html; charset=UTF-8\r\n";
284294
$part .= "Content-Transfer-Encoding: base64\r\n\r\n";
285-
$part .= chunk_split($content)."\r\n";
295+
$part .= chunk_split($content) . "\r\n";
286296
$parts[] = $part;
287297
$parts[] = "--";
288298
$text .= implode("--$boundary", $parts);
@@ -299,7 +309,7 @@ public function getBody()
299309
$part = "\r\nContent-type: {$attachment["mime"]}; name=$name\r\n";
300310
$part .= "Content-Transfer-Encoding: base64\r\n";
301311
$part .= "Content-Disposition: attachment\r\n\r\n";
302-
$part .= chunk_split($attachment["content"])."\r\n";
312+
$part .= chunk_split($attachment["content"]) . "\r\n";
303313
$parts[] = $part;
304314
}
305315
$parts[] = "--";
@@ -317,7 +327,7 @@ public function getPersonalMessages()
317327
{
318328
$result = array();
319329
$recipients = array_replace($this->to, $this->cc, $this->bcc);
320-
foreach ($recipients as $email=>$recipient) {
330+
foreach ($recipients as $email => $recipient) {
321331
$clone = clone $this;
322332
$clone->to = array(
323333
$email => $recipient,
@@ -362,13 +372,23 @@ private function checkEmail($email)
362372
private function addAddress($type, $email, $name)
363373
{
364374
$email = (string)$email;
365-
if (!$email) return false;
366-
if (!$this->checkEmail($email)) return false;
375+
if (!$email) {
376+
return false;
377+
}
378+
if (!$this->checkEmail($email)) {
379+
return false;
380+
}
367381
$contact = $this->getContact($email, $name);
368382
switch ($type) {
369-
case "to": $this->to[$email] = $contact; break;
370-
case "cc": $this->cc[$email] = $contact; break;
371-
case "bcc": $this->bcc[$email] = $contact; break;
383+
case "to":
384+
$this->to[$email] = $contact;
385+
break;
386+
case "cc":
387+
$this->cc[$email] = $contact;
388+
break;
389+
case "bcc":
390+
$this->bcc[$email] = $contact;
391+
break;
372392
}
373393
return true;
374394
}
@@ -391,10 +411,14 @@ private function replaceHeaderBcc()
391411
private function getContact($email, $name = "")
392412
{
393413
$email = (string)$email;
394-
$name = preg_replace("/[^\pL\s\,\.\d]/ui", "", (string)$name);
414+
$name = preg_replace("/[^\pL\s,.\d]/ui", "", (string)$name);
395415
$name = trim($name);
396-
if (preg_match("/[^a-z0-9\s]+/ui", $name)) $name = $this->headerEncode($name);
397-
if ($name) $name = "$name ";
416+
if (preg_match("/[^a-z0-9\s]+/ui", $name)) {
417+
$name = $this->headerEncode($name);
418+
}
419+
if ($name) {
420+
$name = "$name ";
421+
}
398422
return "$name<$email>";
399423
}
400424

@@ -426,7 +450,7 @@ public function unserialize($serialized)
426450
"bcc" => array(),
427451
"boundary" => md5(time()),
428452
);
429-
foreach ($keys as $key=>$default) {
453+
foreach ($keys as $key => $default) {
430454
$this->$key = array_key_exists($key, $raw) ? $raw[$key] : $default;
431455
}
432456
}
@@ -436,4 +460,4 @@ private function headerEncode($value)
436460
$value = mb_encode_mimeheader($value, "UTF-8", "B", "\r\n", 0);
437461
return $value;
438462
}
439-
}
463+
}

src/Spool/FileSpool.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,21 @@ public function add(Message $message, $priority = 0)
7070
public function flush($limit = 0)
7171
{
7272
$limit = (int)$limit;
73-
if ($limit < 1) $limit = 0;
73+
if ($limit < 1) {
74+
$limit = 0;
75+
}
7476
$send = 0;
7577
foreach (glob(implode(DIRECTORY_SEPARATOR, array($this->dir, "mail_???_??????????????_???.eml"))) as $file) {
76-
if ($limit && $send >= $limit) return;
78+
if ($limit && $send >= $limit) {
79+
return;
80+
}
7781
$message = unserialize(base64_decode(file_get_contents($file)));
7882
try {
7983
$this->transport->send($message);
80-
} catch (RecipientsListEmptyException $e) {}
84+
} catch (RecipientsListEmptyException $e) {
85+
}
8186
unlink($file);
8287
$send++;
8388
}
8489
}
85-
}
90+
}

src/Spool/MemorySpool.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ public function send(Message $message)
5757
public function flush($limit = 0)
5858
{
5959
$limit = (int)$limit;
60-
if ($limit < 1) $limit = 0;
60+
if ($limit < 1) {
61+
$limit = 0;
62+
}
6163
$send = 0;
6264
ksort($this->messages);
6365
foreach ($this->messages as $priority => $messages) {
6466
foreach ($messages as $key => $message) {
65-
if ($limit && $send >= $limit) return;
67+
if ($limit && $send >= $limit) {
68+
return;
69+
}
6670
try {
6771
$this->transport->send($message);
68-
} catch (RecipientsListEmptyException $e) {}
72+
} catch (RecipientsListEmptyException $e) {
73+
}
6974
unset($this->messages[$priority][$key]);
7075
$send++;
7176
}
7277
}
7378
}
74-
}
79+
}

src/SpoolInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ public function add(Message $message, $priority = 0);
2727
* @return void
2828
*/
2929
public function flush($limit = null);
30-
}
30+
}

src/Transport/FakeTransport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ public function setLogger(Closure $logger)
3232
{
3333
$this->logger = $logger;
3434
}
35-
}
35+
}

src/Transport/FileTransport.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ final class FileTransport implements TransportInterface
2121

2222
public function __construct($dir)
2323
{
24-
if (!is_dir($dir)) mkdir($dir, 0775, true);
24+
if (!is_dir($dir)) {
25+
mkdir($dir, 0775, true);
26+
}
2527
$this->dir = $dir;
2628
}
2729

@@ -40,7 +42,9 @@ public function send(Message $message)
4042
$user = $arr[0];
4143
$host = $arr[1];
4244
$dir = implode(DIRECTORY_SEPARATOR, array($this->dir, $host, $user));
43-
if (!is_dir($dir)) mkdir($dir, 0644, true);
45+
if (!is_dir($dir)) {
46+
mkdir($dir, 0644, true);
47+
}
4448
$num = 1;
4549
do {
4650
$prefix = "mail_" . date("YmdHis");
@@ -57,4 +61,4 @@ public function setLogger(Closure $logger)
5761
{
5862
$this->logger = $logger;
5963
}
60-
}
64+
}

src/Transport/SendmailTransport.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public function send(Message $message)
3737
if (is_callable($this->logger)) {
3838
$logger = $this->logger;
3939
$log = "mail(";
40-
$log .= "\"".addslashes($to)."\", ";
41-
$log .= "\"".addslashes($subject)."\", ";
42-
$log .= "\"".addslashes($body)."\", ";
43-
$log .= "\"".addslashes($headers)."\", ";
44-
$log .= "\"".addslashes($this->options)."\", ";
40+
$log .= "\"" . addslashes($to) . "\", ";
41+
$log .= "\"" . addslashes($subject) . "\", ";
42+
$log .= "\"" . addslashes($body) . "\", ";
43+
$log .= "\"" . addslashes($headers) . "\", ";
44+
$log .= "\"" . addslashes($this->options) . "\", ";
4545
$log .= ");";
4646
$logger($log);
4747
}
@@ -52,4 +52,4 @@ public function setLogger(Closure $logger)
5252
{
5353
$this->logger = $logger;
5454
}
55-
}
55+
}

0 commit comments

Comments
 (0)