From 13bf197ac75be9fd9e9197806524e3ac2af2ef9b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 29 Sep 2023 02:22:20 +0000 Subject: [PATCH] replace stripos with str_starts_with --- DataStorage/Database/Mapper/ReadMapper.php | 2 +- DataStorage/Database/Query/Grammar/Grammar.php | 2 +- Event/EventManager.php | 8 ++++---- Message/Http/HttpRequest.php | 6 +++--- Message/Http/Rest.php | 2 +- Message/Mail/Email.php | 2 +- Message/Mail/Smtp.php | 2 +- Security/Guard.php | 4 ++-- System/File/FileUtils.php | 4 ++-- Uri/Argument.php | 2 +- Uri/UriFactory.php | 2 +- Utils/Converter/Numeric.php | 2 +- Utils/Parser/Markdown/Markdown.php | 2 +- Utils/Parser/Presentation/PresentationWriter.php | 2 +- 14 files changed, 21 insertions(+), 21 deletions(-) diff --git a/DataStorage/Database/Mapper/ReadMapper.php b/DataStorage/Database/Mapper/ReadMapper.php index 69a17d03d..a5bb79a0d 100755 --- a/DataStorage/Database/Mapper/ReadMapper.php +++ b/DataStorage/Database/Mapper/ReadMapper.php @@ -263,7 +263,7 @@ final class ReadMapper extends DataMapperAbstract $result = $this->executeGet($query); if (\is_object($result) - && (\stripos($class = \get_class($result), 'Null') === 0 || \stripos($class, '\Null') !== false) + && (\str_starts_with($class = \get_class($result), 'Null') || \stripos($class, '\Null') !== false) ) { return []; } diff --git a/DataStorage/Database/Query/Grammar/Grammar.php b/DataStorage/Database/Query/Grammar/Grammar.php index 1e06bc986..e349a6066 100755 --- a/DataStorage/Database/Query/Grammar/Grammar.php +++ b/DataStorage/Database/Query/Grammar/Grammar.php @@ -297,7 +297,7 @@ class Grammar extends GrammarAbstract $expression .= $element['column'](); } elseif ($element['column'] instanceof Where) { $where = \rtrim($this->compileWhereQuery($element['column']), ';'); - $expression .= '(' . (\stripos($where, 'WHERE ') === 0 ? \substr($where, 6) : $where) . ')'; + $expression .= '(' . (\str_starts_with($where, 'WHERE ') ? \substr($where, 6) : $where) . ')'; } elseif ($element['column'] instanceof Builder) { $expression .= '(' . \rtrim($element['column']->toSql(), ';') . ')'; } diff --git a/Event/EventManager.php b/Event/EventManager.php index 164e43fab..bba4b3d73 100755 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -175,12 +175,12 @@ final class EventManager implements \Countable return false; } - $groupIsRegex = \stripos($group, '/') === 0; - $idIsRegex = \stripos($id, '/') === 0; + $groupIsRegex = \str_starts_with($group, '/'); + $idIsRegex = \str_starts_with($id, '/'); $groups = []; foreach ($this->groups as $groupName => $_) { - $groupNameIsRegex = \stripos($groupName, '/') === 0; + $groupNameIsRegex = \str_starts_with($groupName, '/'); if ($groupIsRegex) { if (\preg_match($group, $groupName) === 1) { @@ -195,7 +195,7 @@ final class EventManager implements \Countable foreach ($groups as $groupName => $_) { foreach ($this->groups[$groupName] as $idName => $_2) { - $idNameIsRegex = \stripos($idName, '/') === 0; + $idNameIsRegex = \str_starts_with($idName, '/'); if ($idIsRegex) { if (\preg_match($id, $idName) === 1) { diff --git a/Message/Http/HttpRequest.php b/Message/Http/HttpRequest.php index 47ee659ee..e7ae85f16 100755 --- a/Message/Http/HttpRequest.php +++ b/Message/Http/HttpRequest.php @@ -219,7 +219,7 @@ final class HttpRequest extends RequestAbstract while (($lineRaw = \fgets($stream)) !== false) { // @codeCoverageIgnoreStart // Tested but coverage doesn't show up - if (\strpos($lineRaw, '--') === 0) { + if (\str_starts_with($lineRaw, '--')) { if ($boundary === null) { $boundary = \rtrim($lineRaw); } @@ -254,7 +254,7 @@ final class HttpRequest extends RequestAbstract $lastLine = null; while (($lineRaw = \fgets($stream, 4096)) !== false) { if ($lastLine !== null) { - if ($boundary === null || \strpos($lineRaw, $boundary) === 0) { + if ($boundary === null || \str_starts_with($lineRaw, $boundary)) { break; } @@ -284,7 +284,7 @@ final class HttpRequest extends RequestAbstract $fullValue = ''; $lastLine = null; - while (($lineRaw = \fgets($stream)) !== false && $boundary !== null && \strpos($lineRaw, $boundary) !== 0) { + while (($lineRaw = \fgets($stream)) !== false && $boundary !== null && !\str_starts_with($lineRaw, $boundary)) { if ($lastLine !== null) { $fullValue .= $lastLine; } diff --git a/Message/Http/Rest.php b/Message/Http/Rest.php index c0ec7e116..e7e305ec7 100755 --- a/Message/Http/Rest.php +++ b/Message/Http/Rest.php @@ -121,7 +121,7 @@ final class Rest if (\count($header) < 2) { $response->header->set('', $line = \trim($header[0])); - if (\stripos(\strtoupper($line), 'HTTP/') === 0) { + if (\str_starts_with(\strtoupper($line), 'HTTP/')) { $statusCode = \explode(' ', $line, 3); $response->header->status = (int) $statusCode[1]; } diff --git a/Message/Mail/Email.php b/Message/Mail/Email.php index bb4802090..ff7e85c44 100755 --- a/Message/Mail/Email.php +++ b/Message/Mail/Email.php @@ -2036,7 +2036,7 @@ class Email implements MessageInterface if (!empty($basedir) && (\strpos($url, '..') === false) - && \strpos($url, 'cid:') !== 0 + && !\str_starts_with($url, 'cid:') && !\preg_match('#^[a-z][a-z0-9+.-]*:?//#i', $url) ) { $filename = FileUtils::mb_pathinfo($url, \PATHINFO_BASENAME); diff --git a/Message/Mail/Smtp.php b/Message/Mail/Smtp.php index 12bf3916f..c1496aaca 100755 --- a/Message/Mail/Smtp.php +++ b/Message/Mail/Smtp.php @@ -184,7 +184,7 @@ class Smtp // SMTP server can take longer to respond, give longer timeout for first read // Windows does not have support for this timeout function - if (\strpos(\PHP_OS, 'WIN') !== 0) { + if (!\str_starts_with(\PHP_OS, 'WIN')) { $max = (int) \ini_get('max_execution_time'); if ($max !== 0 && $timeout > $max && \strpos(\ini_get('disable_functions'), 'set_time_limit') === false) { \set_time_limit($timeout); diff --git a/Security/Guard.php b/Security/Guard.php index e6ebe9682..cb80c5cb3 100755 --- a/Security/Guard.php +++ b/Security/Guard.php @@ -50,10 +50,10 @@ final class Guard */ public static function isSafePath(string $path, string $base = '') : bool { - return \stripos( + return \str_starts_with( FileUtils::absolute($path), FileUtils::absolute(empty($base) ? self::$BASE_PATH : $base) - ) === 0; + ); } /** diff --git a/System/File/FileUtils.php b/System/File/FileUtils.php index 9a5e2847c..903fd44e8 100755 --- a/System/File/FileUtils.php +++ b/System/File/FileUtils.php @@ -119,7 +119,7 @@ final class FileUtils return $path === false ? '' : $path; } - $startsWithSlash = \strpos($origPath, '/') === 0 || \strpos($origPath, '\\') === 0 ? '/' : ''; + $startsWithSlash = \str_starts_with($origPath, '/') || \str_starts_with($origPath, '\\') ? '/' : ''; $path = []; $parts = \explode('/', $origPath); @@ -260,7 +260,7 @@ final class FileUtils } $readable = \is_file($path); - if (\strpos($path, '\\\\') !== 0) { + if (!\str_starts_with($path, '\\\\')) { $readable = $readable && \is_readable($path); } diff --git a/Uri/Argument.php b/Uri/Argument.php index 55426691a..addbc7ff4 100755 --- a/Uri/Argument.php +++ b/Uri/Argument.php @@ -170,7 +170,7 @@ final class Argument implements UriInterface $uriParts = \explode(' ', $uri); // Handle no path information only data - $uriParts = \stripos($uriParts[0], '-') === 0 ? ['/', $uriParts[0]] : $uriParts; + $uriParts = \str_starts_with($uriParts[0], '-') ? ['/', $uriParts[0]] : $uriParts; $this->path = empty($uriParts) ? '' : \array_shift($uriParts); $this->pathElements = \explode('/', \ltrim($this->path, '/')); diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 5c4935f2f..7a13ca3b1 100755 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -95,7 +95,7 @@ final class UriFactory self::$uri = []; } else { foreach (self::$uri as $key => $_) { - if (\stripos($key, $identifier) === 0) { + if (\str_starts_with($key, $identifier)) { unset(self::$uri[$key]); } } diff --git a/Utils/Converter/Numeric.php b/Utils/Converter/Numeric.php index 70dc71853..d35a05c50 100755 --- a/Utils/Converter/Numeric.php +++ b/Utils/Converter/Numeric.php @@ -143,7 +143,7 @@ final class Numeric $result = 0; foreach (self::ROMANS as $key => $value) { - while (\strpos($roman, $key) === 0) { + while (\str_starts_with($roman, $key)) { $result += $value; $temp = \substr($roman, \strlen($key)); diff --git a/Utils/Parser/Markdown/Markdown.php b/Utils/Parser/Markdown/Markdown.php index a45df3b8a..a7fd75db7 100755 --- a/Utils/Parser/Markdown/Markdown.php +++ b/Utils/Parser/Markdown/Markdown.php @@ -2895,7 +2895,7 @@ class Markdown return; } - if (\strpos($Line['text'], '