Skip to content

Commit 6c51496

Browse files
joomdonationLadySolveigHLeithner
authored
Use str_contains for libraries code (joomla#44917)
Co-authored-by: Martina Scholz <[email protected]> Co-authored-by: Harald Leithner <[email protected]>
1 parent 9838dcd commit 6c51496

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+79
-79
lines changed

libraries/src/Application/WebApplication.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ protected function loadSystemUris($requestUri = null)
408408
$uri = Uri::getInstance($this->get('uri.request'));
409409

410410
// If we are working from a CGI SAPI with the 'cgi.fix_pathinfo' directive disabled we use PHP_SELF.
411-
if (strpos(PHP_SAPI, 'cgi') !== false && !\ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI'])) {
411+
if (str_contains(PHP_SAPI, 'cgi') && !\ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI'])) {
412412
// We aren't expecting PATH_INFO within PHP_SELF so this should work.
413413
$path = \dirname($_SERVER['PHP_SELF']);
414414
} else {
@@ -420,7 +420,7 @@ protected function loadSystemUris($requestUri = null)
420420
$host = $uri->toString(['scheme', 'user', 'pass', 'host', 'port']);
421421

422422
// Check if the path includes "index.php".
423-
if (strpos($path, 'index.php') !== false) {
423+
if (str_contains($path, 'index.php')) {
424424
// Remove the index.php portion of the path.
425425
$path = substr_replace($path, '', strpos($path, 'index.php'), 9);
426426
}
@@ -441,7 +441,7 @@ protected function loadSystemUris($requestUri = null)
441441
$mediaURI = trim($this->get('media_uri', ''));
442442

443443
if ($mediaURI) {
444-
if (strpos($mediaURI, '://') !== false) {
444+
if (str_contains($mediaURI, '://')) {
445445
$this->set('uri.media.full', $mediaURI);
446446
$this->set('uri.media.path', $mediaURI);
447447
} else {

libraries/src/Authentication/Password/MD5Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function validatePassword($plaintext, $hashed)
8989

9090
// Compile the hash to compare
9191
// If the salt is empty AND there is a ':' in the original hash, we must append ':' at the end
92-
$testcrypt = md5($plaintext . $salt) . ($salt ? ':' . $salt : (strpos($hashed, ':') !== false ? ':' : ''));
92+
$testcrypt = md5($plaintext . $salt) . ($salt ? ':' . $salt : (str_contains($hashed, ':') ? ':' : ''));
9393

9494
return Crypt::timingSafeCompare($hashed, $testcrypt);
9595
}

libraries/src/Client/FtpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ public function syst()
479479
}
480480

481481
// Match the system string to an OS
482-
if (strpos(strtoupper($ret), 'MAC') !== false) {
482+
if (str_contains(strtoupper($ret), 'MAC')) {
483483
$ret = 'MAC';
484-
} elseif (strpos(strtoupper($ret), 'WIN') !== false) {
484+
} elseif (str_contains(strtoupper($ret), 'WIN')) {
485485
$ret = 'WIN';
486486
} else {
487487
$ret = 'UNIX';

libraries/src/Console/SetConfigurationCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function retrieveOptionsFromInput(array $options): bool
127127
$collected = [];
128128

129129
foreach ($options as $option) {
130-
if (strpos($option, '=') === false) {
130+
if (!str_contains($option, '=')) {
131131
$this->ioStyle->error('Options and values should be separated by "="');
132132

133133
return false;

libraries/src/Date/Date.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,19 +312,19 @@ public function format($format, $local = false, $translate = true): string
312312

313313
if ($translate) {
314314
// Manually modify the month and day strings in the formatted time.
315-
if (strpos($return, self::DAY_ABBR) !== false) {
315+
if (str_contains($return, self::DAY_ABBR)) {
316316
$return = str_replace(self::DAY_ABBR, $this->dayToString(parent::format('w'), true), $return);
317317
}
318318

319-
if (strpos($return, self::DAY_NAME) !== false) {
319+
if (str_contains($return, self::DAY_NAME)) {
320320
$return = str_replace(self::DAY_NAME, $this->dayToString(parent::format('w')), $return);
321321
}
322322

323-
if (strpos($return, self::MONTH_ABBR) !== false) {
323+
if (str_contains($return, self::MONTH_ABBR)) {
324324
$return = str_replace(self::MONTH_ABBR, $this->monthToString(parent::format('n'), true), $return);
325325
}
326326

327-
if (strpos($return, self::MONTH_NAME) !== false) {
327+
if (str_contains($return, self::MONTH_NAME)) {
328328
$return = str_replace(self::MONTH_NAME, $this->monthToString(parent::format('n')), $return);
329329
}
330330
}

libraries/src/Dispatcher/ComponentDispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function dispatch()
118118
$command = $this->input->getCmd('task', 'display');
119119

120120
// Check for a controller.task command.
121-
if (strpos($command, '.') !== false) {
121+
if (str_contains($command, '.')) {
122122
// Explode the controller.task command.
123123
list($controller, $task) = explode('.', $command);
124124

libraries/src/Document/Renderer/Feed/RssRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function render($name = '', $params = null, $content = null)
173173
$itemlink = implode('/', array_map('rawurlencode', explode('/', $itemlink)));
174174
}
175175

176-
if ((strpos($itemlink, 'http://') === false) && (strpos($itemlink, 'https://') === false)) {
176+
if ((!str_contains($itemlink, 'http://')) && (!str_contains($itemlink, 'https://'))) {
177177
$itemlink = str_replace(' ', '%20', $url . $itemlink);
178178
}
179179

libraries/src/Document/Renderer/Html/ScriptsRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private function renderElement($item): string
185185
$this->renderedSrc[$src] = true;
186186

187187
// Check if script uses media version.
188-
if ($version && strpos($src, '?') === false && ($mediaVersion || $version !== 'auto')) {
188+
if ($version && !str_contains($src, '?') && ($mediaVersion || $version !== 'auto')) {
189189
$src .= '?' . ($version === 'auto' ? $mediaVersion : $version);
190190
}
191191

libraries/src/Document/Renderer/Html/StylesRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ private function renderElement($item): string
174174
$this->renderedSrc[$src] = true;
175175

176176
// Check if script uses media version.
177-
if ($version && strpos($src, '?') === false && ($mediaVersion || $version !== 'auto')) {
177+
if ($version && !str_contains($src, '?') && ($mediaVersion || $version !== 'auto')) {
178178
$src .= '?' . ($version === 'auto' ? $mediaVersion : $version);
179179
}
180180

libraries/src/Environment/Browser.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,8 @@ public function match($userAgent = null, $accept = null)
543543
* user agent string, which we can use to look for mobile agents.
544544
*/
545545
if (
546-
strpos($this->agent, 'MOT-') !== false
547-
|| strpos($this->lowerAgent, 'j-') !== false
546+
str_contains($this->agent, 'MOT-')
547+
|| str_contains($this->lowerAgent, 'j-')
548548
|| preg_match('/(mobileexplorer|openwave|opera mini|opera mobi|operamini|avantgo|wap|elaine)/i', $this->agent)
549549
|| preg_match('/(iPhone|iPod|iPad|Android|Mobile|Phone|BlackBerry|Xiino|Palmscape|palmsource)/i', $this->agent)
550550
|| preg_match('/(Nokia|Ericsson|docomo|digital paths|portalmmm|CriOS[\/ ]([0-9.]+))/i', $this->agent)
@@ -561,7 +561,7 @@ public function match($userAgent = null, $accept = null)
561561
if (preg_match('|Edge\/([0-9.]+)|', $this->agent, $version)) {
562562
$this->setBrowser('edge');
563563

564-
if (strpos($version[1], '.') !== false) {
564+
if (str_contains($version[1], '.')) {
565565
list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
566566
} else {
567567
$this->majorVersion = $version[1];
@@ -601,9 +601,9 @@ public function match($userAgent = null, $accept = null)
601601

602602
list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
603603
} elseif (
604-
strpos($this->lowerAgent, 'elaine/') !== false
605-
|| strpos($this->lowerAgent, 'palmsource') !== false
606-
|| strpos($this->lowerAgent, 'digital paths') !== false
604+
str_contains($this->lowerAgent, 'elaine/')
605+
|| str_contains($this->lowerAgent, 'palmsource')
606+
|| str_contains($this->lowerAgent, 'digital paths')
607607
) {
608608
$this->setBrowser('palm');
609609
} elseif (
@@ -615,11 +615,11 @@ public function match($userAgent = null, $accept = null)
615615
$this->setBrowser('msie');
616616

617617
// Special case for IE 11+
618-
if (strpos($version[0], 'Trident') !== false && strpos($version[0], 'rv:') !== false) {
618+
if (str_contains($version[0], 'Trident') && str_contains($version[0], 'rv:')) {
619619
preg_match('|rv:([0-9.]+)|', $this->agent, $version);
620620
}
621621

622-
if (strpos($version[1], '.') !== false) {
622+
if (str_contains($version[1], '.')) {
623623
list($this->majorVersion, $this->minorVersion) = explode('.', $version[1]);
624624
} else {
625625
$this->majorVersion = $version[1];
@@ -634,7 +634,7 @@ public function match($userAgent = null, $accept = null)
634634
}
635635
} elseif (preg_match('|ANTFresco\/([0-9]+)|', $this->agent, $version)) {
636636
$this->setBrowser('fresco');
637-
} elseif (strpos($this->lowerAgent, 'avantgo') !== false) {
637+
} elseif (str_contains($this->lowerAgent, 'avantgo')) {
638638
$this->setBrowser('avantgo');
639639
} elseif (preg_match('|[Kk]onqueror\/([0-9]+)|', $this->agent, $version) || preg_match('|Safari/([0-9]+)\.?([0-9]+)?|', $this->agent, $version)) {
640640
// Konqueror and Apple's Safari both use the KHTML rendering engine.
@@ -645,7 +645,7 @@ public function match($userAgent = null, $accept = null)
645645
$this->minorVersion = $version[2];
646646
}
647647

648-
if (strpos($this->agent, 'Safari') !== false && $this->majorVersion >= 60) {
648+
if (str_contains($this->agent, 'Safari') && $this->majorVersion >= 60) {
649649
// Safari.
650650
$this->setBrowser('safari');
651651
$this->identifyBrowserVersion();
@@ -660,25 +660,25 @@ public function match($userAgent = null, $accept = null)
660660
$this->setBrowser('links');
661661
} elseif (preg_match('|HotJava\/([0-9]+)|', $this->agent, $version)) {
662662
$this->setBrowser('hotjava');
663-
} elseif (strpos($this->agent, 'UP/') !== false || strpos($this->agent, 'UP.B') !== false || strpos($this->agent, 'UP.L') !== false) {
663+
} elseif (str_contains($this->agent, 'UP/') || str_contains($this->agent, 'UP.B') || str_contains($this->agent, 'UP.L')) {
664664
$this->setBrowser('up');
665-
} elseif (strpos($this->agent, 'Xiino/') !== false) {
665+
} elseif (str_contains($this->agent, 'Xiino/')) {
666666
$this->setBrowser('xiino');
667-
} elseif (strpos($this->agent, 'Palmscape/') !== false) {
667+
} elseif (str_contains($this->agent, 'Palmscape/')) {
668668
$this->setBrowser('palmscape');
669-
} elseif (strpos($this->agent, 'Nokia') !== false) {
669+
} elseif (str_contains($this->agent, 'Nokia')) {
670670
$this->setBrowser('nokia');
671-
} elseif (strpos($this->agent, 'Ericsson') !== false) {
671+
} elseif (str_contains($this->agent, 'Ericsson')) {
672672
$this->setBrowser('ericsson');
673-
} elseif (strpos($this->lowerAgent, 'wap') !== false) {
673+
} elseif (str_contains($this->lowerAgent, 'wap')) {
674674
$this->setBrowser('wap');
675-
} elseif (strpos($this->lowerAgent, 'docomo') !== false || strpos($this->lowerAgent, 'portalmmm') !== false) {
675+
} elseif (str_contains($this->lowerAgent, 'docomo') || str_contains($this->lowerAgent, 'portalmmm')) {
676676
$this->setBrowser('imode');
677-
} elseif (strpos($this->agent, 'BlackBerry') !== false) {
677+
} elseif (str_contains($this->agent, 'BlackBerry')) {
678678
$this->setBrowser('blackberry');
679-
} elseif (strpos($this->agent, 'MOT-') !== false) {
679+
} elseif (str_contains($this->agent, 'MOT-')) {
680680
$this->setBrowser('motorola');
681-
} elseif (strpos($this->lowerAgent, 'j-') !== false) {
681+
} elseif (str_contains($this->lowerAgent, 'j-')) {
682682
$this->setBrowser('mml');
683683
} elseif (preg_match('|Mozilla\/([0-9.]+)|', $this->agent, $version)) {
684684
$this->setBrowser('mozilla');
@@ -701,9 +701,9 @@ public function match($userAgent = null, $accept = null)
701701
*/
702702
protected function _setPlatform()
703703
{
704-
if (strpos($this->lowerAgent, 'wind') !== false) {
704+
if (str_contains($this->lowerAgent, 'wind')) {
705705
$this->platform = 'win';
706-
} elseif (strpos($this->lowerAgent, 'mac') !== false) {
706+
} elseif (str_contains($this->lowerAgent, 'mac')) {
707707
$this->platform = 'mac';
708708
} else {
709709
$this->platform = 'unix';
@@ -854,11 +854,11 @@ public function isViewable($mimetype)
854854
if (!empty($this->accept)) {
855855
$wildcard_match = false;
856856

857-
if (strpos($this->accept, $mimetype) !== false) {
857+
if (str_contains($this->accept, $mimetype)) {
858858
return true;
859859
}
860860

861-
if (strpos($this->accept, '*/*') !== false) {
861+
if (str_contains($this->accept, '*/*')) {
862862
$wildcard_match = true;
863863

864864
if ($type !== 'image') {
@@ -867,7 +867,7 @@ public function isViewable($mimetype)
867867
}
868868

869869
// Deal with Mozilla pjpeg/jpeg issue
870-
if ($this->isBrowser('mozilla') && ($mimetype === 'image/pjpeg') && (strpos($this->accept, 'image/jpeg') !== false)) {
870+
if ($this->isBrowser('mozilla') && ($mimetype === 'image/pjpeg') && (str_contains($this->accept, 'image/jpeg'))) {
871871
return true;
872872
}
873873

0 commit comments

Comments
 (0)