Skip to content

Commit 828bdf7

Browse files
committed
coding style: TRUE/FALSE/NULL -> true/false/null
1 parent 124e153 commit 828bdf7

File tree

10 files changed

+55
-55
lines changed

10 files changed

+55
-55
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ $mail->setHTMLBody('<b>Sample HTML</b> <img src="background.gif">');
5858

5959
Embedded images can be inserted using `$mail->addEmbeddedFile('background.gif')`, but it is not necessary.
6060
Why? Because Nette Framework finds and inserts all files referenced in the HTML code automatically.
61-
This behavior can be supressed by adding `FALSE` as a second parameter of the `setHtmlBody()` method.
61+
This behavior can be supressed by adding `false` as a second parameter of the `setHtmlBody()` method.
6262

6363
If a HTML e-mail has no plain-text alternative, it will be automatically generated. And if it has no subject set, it will be taken from the `<title>` element.
6464

src/Bridges/MailDI/MailExtension.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
class MailExtension extends Nette\DI\CompilerExtension
1919
{
2020
public $defaults = [
21-
'smtp' => FALSE,
22-
'host' => NULL,
23-
'port' => NULL,
24-
'username' => NULL,
25-
'password' => NULL,
26-
'secure' => NULL,
27-
'timeout' => NULL,
28-
'context' => NULL,
21+
'smtp' => false,
22+
'host' => null,
23+
'port' => null,
24+
'username' => null,
25+
'password' => null,
26+
'secure' => null,
27+
'timeout' => null,
28+
'context' => null,
2929
];
3030

3131

src/Mail/Message.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct()
5555
* Sets the sender of the message. Email or format "John Doe" <[email protected]>
5656
* @return static
5757
*/
58-
public function setFrom(string $email, string $name = NULL)
58+
public function setFrom(string $email, string $name = null)
5959
{
6060
$this->setHeader('From', $this->formatEmail($email, $name));
6161
return $this;
@@ -75,9 +75,9 @@ public function getFrom(): array
7575
* Adds the reply-to address. Email or format "John Doe" <[email protected]>
7676
* @return static
7777
*/
78-
public function addReplyTo(string $email, string $name = NULL)
78+
public function addReplyTo(string $email, string $name = null)
7979
{
80-
$this->setHeader('Reply-To', $this->formatEmail($email, $name), TRUE);
80+
$this->setHeader('Reply-To', $this->formatEmail($email, $name), true);
8181
return $this;
8282
}
8383

@@ -106,9 +106,9 @@ public function getSubject(): ?string
106106
* Adds email recipient. Email or format "John Doe" <[email protected]>
107107
* @return static
108108
*/
109-
public function addTo(string $email, string $name = NULL) // addRecipient()
109+
public function addTo(string $email, string $name = null) // addRecipient()
110110
{
111-
$this->setHeader('To', $this->formatEmail($email, $name), TRUE);
111+
$this->setHeader('To', $this->formatEmail($email, $name), true);
112112
return $this;
113113
}
114114

@@ -117,9 +117,9 @@ public function addTo(string $email, string $name = NULL) // addRecipient()
117117
* Adds carbon copy email recipient. Email or format "John Doe" <[email protected]>
118118
* @return static
119119
*/
120-
public function addCc(string $email, string $name = NULL)
120+
public function addCc(string $email, string $name = null)
121121
{
122-
$this->setHeader('Cc', $this->formatEmail($email, $name), TRUE);
122+
$this->setHeader('Cc', $this->formatEmail($email, $name), true);
123123
return $this;
124124
}
125125

@@ -128,17 +128,17 @@ public function addCc(string $email, string $name = NULL)
128128
* Adds blind carbon copy email recipient. Email or format "John Doe" <[email protected]>
129129
* @return static
130130
*/
131-
public function addBcc(string $email, string $name = NULL)
131+
public function addBcc(string $email, string $name = null)
132132
{
133-
$this->setHeader('Bcc', $this->formatEmail($email, $name), TRUE);
133+
$this->setHeader('Bcc', $this->formatEmail($email, $name), true);
134134
return $this;
135135
}
136136

137137

138138
/**
139139
* Formats recipient email.
140140
*/
141-
private function formatEmail(string $email, string $name = NULL): array
141+
private function formatEmail(string $email, string $name = null): array
142142
{
143143
if (!$name && preg_match('#^(.+) +<(.*)>\z#', $email, $matches)) {
144144
return [$matches[2] => $matches[1]];
@@ -192,7 +192,7 @@ public function getPriority(): int
192192
* Sets HTML body.
193193
* @return static
194194
*/
195-
public function setHtmlBody(string $html, string $basePath = NULL)
195+
public function setHtmlBody(string $html, string $basePath = null)
196196
{
197197
if ($basePath) {
198198
$cids = [];
@@ -220,7 +220,7 @@ public function setHtmlBody(string $html, string $basePath = NULL)
220220
}
221221
}
222222

223-
if ($this->getSubject() == NULL) { // intentionally ==
223+
if ($this->getSubject() == null) { // intentionally ==
224224
$html = Strings::replace($html, '#<title>(.+?)</title>#is', function ($m) {
225225
$this->setSubject(html_entity_decode($m[1], ENT_QUOTES, 'UTF-8'));
226226
});
@@ -248,7 +248,7 @@ public function getHtmlBody(): string
248248
/**
249249
* Adds embedded file.
250250
*/
251-
public function addEmbeddedFile(string $file, string $content = NULL, string $contentType = NULL): MimePart
251+
public function addEmbeddedFile(string $file, string $content = null, string $contentType = null): MimePart
252252
{
253253
return $this->inlines[$file] = $this->createAttachment($file, $content, $contentType, 'inline')
254254
->setHeader('Content-ID', $this->getRandomId());
@@ -269,7 +269,7 @@ public function addInlinePart(MimePart $part)
269269
/**
270270
* Adds attachment.
271271
*/
272-
public function addAttachment(string $file, string $content = NULL, string $contentType = NULL): MimePart
272+
public function addAttachment(string $file, string $content = null, string $contentType = null): MimePart
273273
{
274274
return $this->attachments[] = $this->createAttachment($file, $content, $contentType, 'attachment');
275275
}
@@ -288,12 +288,12 @@ public function getAttachments(): array
288288
/**
289289
* Creates file MIME part.
290290
*/
291-
private function createAttachment(string $file, string $content = NULL, string $contentType = NULL, string $disposition): MimePart
291+
private function createAttachment(string $file, string $content = null, string $contentType = null, string $disposition): MimePart
292292
{
293293
$part = new MimePart;
294-
if ($content === NULL) {
294+
if ($content === null) {
295295
$content = @file_get_contents($file); // @ is escalated to exception
296-
if ($content === FALSE) {
296+
if ($content === false) {
297297
throw new Nette\FileNotFoundException("Unable to read file '$file'.");
298298
}
299299
}

src/Mail/MimePart.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class MimePart
4747
* @param string|array $value value or pair email => name
4848
* @return static
4949
*/
50-
public function setHeader(string $name, $value, bool $append = FALSE)
50+
public function setHeader(string $name, $value, bool $append = false)
5151
{
5252
if (!$name || preg_match('#[^a-z0-9-]#i', $name)) {
5353
throw new Nette\InvalidArgumentException("Header name must be non-empty alphanumeric string, '$name' given.");
5454
}
5555

56-
if ($value == NULL) { // intentionally ==
56+
if ($value == null) { // intentionally ==
5757
if (!$append) {
5858
unset($this->headers[$name]);
5959
}
@@ -65,7 +65,7 @@ public function setHeader(string $name, $value, bool $append = FALSE)
6565
}
6666

6767
foreach ($value as $email => $recipient) {
68-
if ($recipient === NULL) {
68+
if ($recipient === null) {
6969
// continue
7070
} elseif (!Strings::checkEncoding($recipient)) {
7171
Nette\Utils\Validators::assert($recipient, 'unicode', "header '$name'");
@@ -93,7 +93,7 @@ public function setHeader(string $name, $value, bool $append = FALSE)
9393
*/
9494
public function getHeader(string $name)
9595
{
96-
return $this->headers[$name] ?? NULL;
96+
return $this->headers[$name] ?? null;
9797
}
9898

9999

@@ -116,13 +116,13 @@ public function getEncodedHeader(string $name): ?string
116116
$offset = strlen($name) + 2; // colon + space
117117

118118
if (!isset($this->headers[$name])) {
119-
return NULL;
119+
return null;
120120

121121
} elseif (is_array($this->headers[$name])) {
122122
$s = '';
123123
foreach ($this->headers[$name] as $email => $name) {
124-
if ($name != NULL) { // intentionally ==
125-
$s .= self::encodeHeader($name, $offset, TRUE);
124+
if ($name != null) { // intentionally ==
125+
$s .= self::encodeHeader($name, $offset, true);
126126
$email = " <$email>";
127127
}
128128
$s .= self::append($email . ',', $offset);
@@ -152,7 +152,7 @@ public function getHeaders(): array
152152
* Sets Content-Type header.
153153
* @return static
154154
*/
155-
public function setContentType(string $contentType, string $charset = NULL)
155+
public function setContentType(string $contentType, string $charset = null)
156156
{
157157
$this->setHeader('Content-Type', $contentType . ($charset ? "; charset=$charset" : ''));
158158
return $this;
@@ -182,9 +182,9 @@ public function getEncoding(): string
182182
/**
183183
* Adds or creates new multipart.
184184
*/
185-
public function addPart(MimePart $part = NULL): self
185+
public function addPart(MimePart $part = null): self
186186
{
187-
return $this->parts[] = $part === NULL ? new self : $part;
187+
return $this->parts[] = $part === null ? new self : $part;
188188
}
189189

190190

@@ -274,7 +274,7 @@ public function getEncodedMessage(): string
274274
/**
275275
* Converts a 8 bit header to a string.
276276
*/
277-
private static function encodeHeader(string $s, int &$offset = 0, bool $quotes = FALSE): string
277+
private static function encodeHeader(string $s, int &$offset = 0, bool $quotes = false): string
278278
{
279279
if (strspn($s, "!\"#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\r\n\t") === strlen($s)) {
280280
if ($quotes && preg_match('#[^ a-zA-Z0-9!\#$%&\'*+/?^_`{|}~-]#', $s)) { // RFC 2822 atext except =

src/Mail/SendmailMailer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SendmailMailer implements IMailer
1919
{
2020
use Nette\SmartObject;
2121

22-
/** @var string|NULL */
22+
/** @var string|null */
2323
public $commandArgs;
2424

2525

@@ -30,8 +30,8 @@ class SendmailMailer implements IMailer
3030
public function send(Message $mail): void
3131
{
3232
$tmp = clone $mail;
33-
$tmp->setHeader('Subject', NULL);
34-
$tmp->setHeader('To', NULL);
33+
$tmp->setHeader('Subject', null);
34+
$tmp->setHeader('To', null);
3535

3636
$parts = explode(Message::EOL . Message::EOL, $tmp->generateMessage(), 2);
3737

@@ -47,7 +47,7 @@ public function send(Message $mail): void
4747
$res = Nette\Utils\Callback::invokeSafe('mail', $args, function ($message) use (&$info) {
4848
$info = ": $message";
4949
});
50-
if ($res === FALSE) {
50+
if ($res === false) {
5151
throw new SendException("Unable to send email$info.");
5252
}
5353
}

src/Mail/SmtpMailer.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(array $options = [])
5151
{
5252
if (isset($options['host'])) {
5353
$this->host = $options['host'];
54-
$this->port = isset($options['port']) ? (int) $options['port'] : NULL;
54+
$this->port = isset($options['port']) ? (int) $options['port'] : null;
5555
} else {
5656
$this->host = ini_get('SMTP');
5757
$this->port = (int) ini_get('smtp_port');
@@ -95,7 +95,7 @@ public function send(Message $mail): void
9595
$this->write("RCPT TO:<$email>", [250, 251]);
9696
}
9797

98-
$mail->setHeader('Bcc', NULL);
98+
$mail->setHeader('Bcc', null);
9999
$data = $mail->generateMessage();
100100
$this->write('DATA', 354);
101101
$data = preg_replace('#^\.#m', '..', $data);
@@ -139,19 +139,19 @@ protected function connect(): void
139139

140140
if ($this->secure === 'tls') {
141141
$this->write('STARTTLS', 220);
142-
if (!stream_socket_enable_crypto($this->connection, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
142+
if (!stream_socket_enable_crypto($this->connection, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
143143
throw new SmtpException('Unable to connect via TLS.');
144144
}
145145
$this->write("EHLO $self", 250);
146146
}
147147

148-
if ($this->username != NULL && $this->password != NULL) {
148+
if ($this->username != null && $this->password != null) {
149149
$authMechanisms = [];
150150
if (preg_match('~^250[ -]AUTH (.*)$~im', $ehloResponse, $matches)) {
151151
$authMechanisms = explode(' ', trim($matches[1]));
152152
}
153153

154-
if (in_array('PLAIN', $authMechanisms, TRUE)) {
154+
if (in_array('PLAIN', $authMechanisms, true)) {
155155
$credentials = $this->username . "\0" . $this->username . "\0" . $this->password;
156156
$this->write('AUTH PLAIN ' . base64_encode($credentials), 235, 'PLAIN credentials');
157157
} else {
@@ -169,20 +169,20 @@ protected function connect(): void
169169
protected function disconnect(): void
170170
{
171171
fclose($this->connection);
172-
$this->connection = NULL;
172+
$this->connection = null;
173173
}
174174

175175

176176
/**
177177
* Writes data to server and checks response against expected code if some provided.
178178
* @param int|int[] $expectedCode
179179
*/
180-
protected function write(string $line, $expectedCode = NULL, string $message = NULL): void
180+
protected function write(string $line, $expectedCode = null, string $message = null): void
181181
{
182182
fwrite($this->connection, $line . Message::EOL);
183183
if ($expectedCode) {
184184
$response = $this->read();
185-
if (!in_array((int) $response, (array) $expectedCode, TRUE)) {
185+
if (!in_array((int) $response, (array) $expectedCode, true)) {
186186
throw new SmtpException('SMTP server did not accept ' . ($message ? $message : $line) . ' with error: ' . trim($response));
187187
}
188188
}
@@ -195,7 +195,7 @@ protected function write(string $line, $expectedCode = NULL, string $message = N
195195
protected function read(): string
196196
{
197197
$s = '';
198-
while (($line = fgets($this->connection, 1000)) != NULL) { // intentionally ==
198+
while (($line = fgets($this->connection, 1000)) != null) { // intentionally ==
199199
$s .= $line;
200200
if (substr($line, 3, 1) === ' ') {
201201
break;

tests/Mail.DI/include.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class FooExtension extends Nette\DI\CompilerExtension
88
}
99

1010

11-
function createContainer($source, $config = NULL)
11+
function createContainer($source, $config = null)
1212
{
1313
$loader = new Nette\DI\Config\Loader;
1414
$config = $loader->load(Tester\FileMock::create($config, 'neon'));

tests/Mail/Mail.attachment.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require __DIR__ . '/Mail.php';
1818
$mailer = new TestMailer();
1919

2020
$mail = new Message();
21-
$mail->addAttachment(__DIR__ . '/files/example.zip', NULL, 'application/zip');
21+
$mail->addAttachment(__DIR__ . '/files/example.zip', null, 'application/zip');
2222
$mailer->send($mail);
2323

2424
Assert::match(<<<EOD
@@ -49,7 +49,7 @@ EOD
4949

5050

5151
$mail = new Message();
52-
$mail->addAttachment(__DIR__ . '/files/example.zip', NULL, 'application/zip')
52+
$mail->addAttachment(__DIR__ . '/files/example.zip', null, 'application/zip')
5353
->setEncoding(Message::ENCODING_QUOTED_PRINTABLE);
5454
$mailer->send($mail);
5555

tests/Mail/Mail.textualAndHtmlBody.attachment.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $mail->setBody('Sample text');
2525

2626
$mail->setHTMLBody('<b>Sample text</b>');
2727

28-
$mail->addAttachment(__DIR__ . '/files/example.zip', NULL, 'application/zip');
28+
$mail->addAttachment(__DIR__ . '/files/example.zip', null, 'application/zip');
2929

3030
$mailer = new TestMailer();
3131
$mailer->send($mail);

tests/Mail/Mail.textualBody.attachment.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ $mail->setSubject('Hello Jane!');
2323

2424
$mail->setBody('Sample text');
2525

26-
$mail->addAttachment(__DIR__ . '/files/example.zip', NULL, 'application/zip');
26+
$mail->addAttachment(__DIR__ . '/files/example.zip', null, 'application/zip');
2727

2828
$mailer = new TestMailer();
2929
$mailer->send($mail);

0 commit comments

Comments
 (0)