Skip to content

Commit 4b5efac

Browse files
committed
refactor: more !== 1 compare on preg_match()
1 parent 77f0b39 commit 4b5efac

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

system/Email/Email.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ public function setFrom($from, $name = '', $returnPath = null)
495495

496496
if ($name !== '') {
497497
// only use Q encoding if there are characters that would require it
498-
if (in_array(preg_match('/[\200-\377]/', $name), [0, false], true)) {
498+
if (preg_match('/[\200-\377]/', $name) !== 1) {
499499
$name = '"' . addcslashes($name, "\0..\37\177'\"\\") . '"';
500500
} else {
501501
$name = $this->prepQEncoding($name);
@@ -532,7 +532,7 @@ public function setReplyTo($replyto, $name = '')
532532
$this->tmpArchive['replyName'] = $name;
533533

534534
// only use Q encoding if there are characters that would require it
535-
if (in_array(preg_match('/[\200-\377]/', $name), [0, false], true)) {
535+
if (preg_match('/[\200-\377]/', $name) !== 1) {
536536
$name = '"' . addcslashes($name, "\0..\37\177'\"\\") . '"';
537537
} else {
538538
$name = $this->prepQEncoding($name);

system/Helpers/html_helper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function img($src = '', bool $indexPage = false, $attributes = ''): string
112112
$img = '<img';
113113

114114
// Check for a relative URI
115-
if (in_array(preg_match('#^([a-z]+:)?//#i', $src['src']), [0, false], true) && ! str_starts_with($src['src'], 'data:')) {
115+
if (preg_match('#^([a-z]+:)?//#i', $src['src']) !== 1 && ! str_starts_with($src['src'], 'data:')) {
116116
if ($indexPage) {
117117
$img .= ' src="' . site_url($src['src']) . '"';
118118
} else {
@@ -206,7 +206,7 @@ function script_tag($src = '', bool $indexPage = false): string
206206
}
207207

208208
foreach ($src as $k => $v) {
209-
if ($k === 'src' && in_array(preg_match('#^([a-z]+:)?//#i', $v), [0, false], true)) {
209+
if ($k === 'src' && preg_match('#^([a-z]+:)?//#i', $v) !== 1) {
210210
if ($indexPage) {
211211
$script .= 'src="' . site_url($v) . '" ';
212212
} else {
@@ -252,7 +252,7 @@ function link_tag(
252252
$href = $href['href'] ?? '';
253253
}
254254

255-
if (in_array(preg_match('#^([a-z]+:)?//#i', $href), [0, false], true)) {
255+
if (preg_match('#^([a-z]+:)?//#i', $href) !== 1) {
256256
$attributes['href'] = $indexPage ? site_url($href) : slash_item('baseURL') . $href;
257257
} else {
258258
$attributes['href'] = $href;

system/Router/RouteCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ protected function buildReverseRoute(string $from, array $params): string
13911391
// or maybe $placeholder is not a placeholder, but a regex.
13921392
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;
13931393

1394-
if (in_array(preg_match('#^' . $pattern . '$#u', (string) $params[$index]), [0, false], true)) {
1394+
if (preg_match('#^' . $pattern . '$#u', (string) $params[$index]) !== 1) {
13951395
throw RouterException::forInvalidParameterType();
13961396
}
13971397

system/Session/Handlers/FileHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function gc($max_lifetime)
290290

291291
while (($file = readdir($directory)) !== false) {
292292
// If the filename doesn't match this pattern, it's either not a session file or is not ours
293-
if (in_array(preg_match($pattern, $file), [0, false], true)
293+
if (preg_match($pattern, $file) !== 1
294294
|| ! is_file($this->savePath . DIRECTORY_SEPARATOR . $file)
295295
|| ($mtime = filemtime($this->savePath . DIRECTORY_SEPARATOR . $file)) === false
296296
|| $mtime > $ts

system/Session/Session.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function start()
234234

235235
// Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers
236236
if (isset($_COOKIE[$this->config->cookieName])
237-
&& (! is_string($_COOKIE[$this->config->cookieName]) || in_array(preg_match('#\A' . $this->sidRegexp . '\z#', $_COOKIE[$this->config->cookieName]), [0, false], true))
237+
&& (! is_string($_COOKIE[$this->config->cookieName]) || preg_match('#\A' . $this->sidRegexp . '\z#', $_COOKIE[$this->config->cookieName]) !== 1)
238238
) {
239239
unset($_COOKIE[$this->config->cookieName]);
240240
}

system/Typography/Typography.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function autoTypography(string $str, bool $reduceLinebreaks = false): str
171171
}
172172

173173
// No opening block level tag? Add it if needed.
174-
if (in_array(preg_match('/^\s*<(?:' . $this->blockElements . ')/i', $str), [0, false], true)) {
174+
if (preg_match('/^\s*<(?:' . $this->blockElements . ')/i', $str) !== 1) {
175175
$str = preg_replace('/^(.*?)<(' . $this->blockElements . ')/i', '<p>$1</p><$2', $str);
176176
}
177177

0 commit comments

Comments
 (0)