Skip to content

Commit

Permalink
coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 2, 2020
1 parent 439a305 commit e072486
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 38 deletions.
4 changes: 3 additions & 1 deletion src/Mail/DkimSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public function __construct(array $options, array $signHeaders = self::DEFAULT_S
$this->selector = $options['selector'] ?? '';
$this->privateKey = $options['privateKey'] ?? '';
$this->passPhrase = $options['passPhrase'] ?? '';
$this->signHeaders = count($signHeaders) > 0 ? $signHeaders : self::DEFAULT_SIGN_HEADERS;
$this->signHeaders = count($signHeaders) > 0
? $signHeaders
: self::DEFAULT_SIGN_HEADERS;
}


Expand Down
14 changes: 10 additions & 4 deletions src/Mail/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,11 @@ public function setHtmlBody(string $html, string $basePath = null)
if (!isset($cids[$file])) {
$cids[$file] = substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1);
}
$html = substr_replace($html,
$html = substr_replace(
$html,
"{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}",
$m[0][1], strlen($m[0][0])
$m[0][1],
strlen($m[0][0])
);
}
}
Expand Down Expand Up @@ -293,8 +295,12 @@ public function getAttachments(): array
/**
* Creates file MIME part.
*/
private function createAttachment(string $file, ?string $content, ?string $contentType, string $disposition): MimePart
{
private function createAttachment(
string $file,
?string $content,
?string $contentType,
string $disposition
): MimePart {
$part = new MimePart;
if ($content === null) {
$content = Nette\Utils\FileSystem::read($file);
Expand Down
4 changes: 2 additions & 2 deletions src/Mail/MimePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function getEncoding(): string
*/
public function addPart(self $part = null): self
{
return $this->parts[] = $part === null ? new self : $part;
return $this->parts[] = $part ?? new self;
}


Expand Down Expand Up @@ -284,7 +284,7 @@ private static function encodeSequence(string $s, int &$offset = 0, int $type =
{
if (
(strlen($s) < self::LINE_LENGTH - 3) && // 3 is tab + quotes
strspn($s, "!\"#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\r\n\t") === strlen($s)
strspn($s, "!\"#$%&\\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\r\n\t") === strlen($s)
) {
if ($type && preg_match('#[^ a-zA-Z0-9!\#$%&\'*+/?^_`{|}~-]#', $s)) { // RFC 2822 atext except =
return self::append('"' . addcslashes($s, '"\\') . '"', $offset);
Expand Down
18 changes: 14 additions & 4 deletions src/Mail/SmtpMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,22 @@ public function __construct(array $options = [])
{
if (isset($options['host'])) {
$this->host = $options['host'];
$this->port = isset($options['port']) ? (int) $options['port'] : null;
$this->port = isset($options['port'])
? (int) $options['port']
: null;
} else {
$this->host = ini_get('SMTP');
$this->port = (int) ini_get('smtp_port');
}
$this->username = $options['username'] ?? '';
$this->password = $options['password'] ?? '';
$this->secure = $options['secure'] ?? '';
$this->timeout = isset($options['timeout']) ? (int) $options['timeout'] : 20;
$this->context = isset($options['context']) ? stream_context_create($options['context']) : stream_context_get_default();
$this->timeout = isset($options['timeout'])
? (int) $options['timeout']
: 20;
$this->context = isset($options['context'])
? stream_context_create($options['context'])
: stream_context_get_default();
if (!$this->port) {
$this->port = $this->secure === 'ssl' ? 465 : 25;
}
Expand Down Expand Up @@ -147,7 +153,11 @@ protected function connect(): void
{
$this->connection = @stream_socket_client(// @ is escalated to exception
($this->secure === 'ssl' ? 'ssl://' : '') . $this->host . ':' . $this->port,
$errno, $error, $this->timeout, STREAM_CLIENT_CONNECT, $this->context
$errno,
$error,
$this->timeout,
STREAM_CLIENT_CONNECT,
$this->context
);
if (!$this->connection) {
throw new SmtpException($error ?: error_get_last()['message'], $errno);
Expand Down
10 changes: 1 addition & 9 deletions tests/Mail/Mail.dkim.headers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ if (!extension_loaded('openssl')) {
Tester\Environment::skip('OpenSSL not installed');
}

$signer = new class ([], [
'From',
'To',
'Date',
'Subject',
'Message-ID',
'X-Mailer',
'Content-Type',
]) extends DkimSigner {
$signer = new class([], ['From', 'To', 'Date', 'Subject', 'Message-ID', 'X-Mailer', 'Content-Type']) extends DkimSigner {
public function getSignedHeaders(Message $message): array
{
return parent::getSignedHeaders($message);
Expand Down
8 changes: 1 addition & 7 deletions tests/Mail/Mail.dkim.process.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ if (!extension_loaded('openssl')) {
Tester\Environment::skip('OpenSSL not installed');
}

$signer = new class ([], [
'From',
'To',
'Subject',
'X-Mailer',
'Content-Type',
]) extends DkimSigner {
$signer = new class([], ['From', 'To', 'Subject', 'X-Mailer', 'Content-Type']) extends DkimSigner {
public function computeSignature(string $rawHeader, string $signature): string
{
$headers = parent::computeSignature($rawHeader, $signature);
Expand Down
10 changes: 1 addition & 9 deletions tests/Mail/Mail.dkim.sign.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,7 @@ $mail->addTo('Lady Jane <[email protected]>');
$mail->setSubject('Hello Jane!');
$mail->setBody('Příliš žluťoučký kůň');

$signer = new class ([
'privateKey' => $privateKey,
'domain' => 'nette.org',
'selector' => 'selector',
], [
'From',
'To',
'Subject',
]) extends DkimSigner {
$signer = new class(['privateKey' => $privateKey, 'domain' => 'nette.org', 'selector' => 'selector'], ['From', 'To', 'Subject']) extends DkimSigner {
protected function getTime(): int
{
return 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/Mail/Mail.textualAndHtmlBody.embedded.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $mail->setHTMLBody("
<a href='test.php?src=SOME'>some link</a>
<script src=script.js></script>
<div title=\"background:url(background.png)\">
<style></style> background: url(\'background.png\');
<style></style> background: url(\\'background.png\\');
[[backgroun%64.png]]
", __DIR__ . '/fixtures');

Expand Down
2 changes: 1 addition & 1 deletion tests/Mail/SendmailMailer.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ require __DIR__ . '/../bootstrap.php';

Assert::exception(function () {
$sendmailMailer = new Nette\Mail\SendmailMailer;
$message = new Message();
$message = new Message;
$sendmailMailer->send($message);
}, Nette\Mail\SendException::class, 'Unable to send email: mail() has been disabled.');

0 comments on commit e072486

Please sign in to comment.