diff --git a/lib/private/DB/OracleMigrator.php b/lib/private/DB/OracleMigrator.php index 18deb97ec26f3..4828110074cf2 100644 --- a/lib/private/DB/OracleMigrator.php +++ b/lib/private/DB/OracleMigrator.php @@ -206,7 +206,7 @@ protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $conn * @return string */ protected function convertStatementToScript($statement) { - if (substr($statement, -1) === ';') { + if (str_ends_with($statement, ';')) { return $statement . PHP_EOL . '/' . PHP_EOL; } $script = $statement . ';'; diff --git a/lib/private/DateTimeFormatter.php b/lib/private/DateTimeFormatter.php index 1c8b4f6d3abb9..57c4833a4e357 100644 --- a/lib/private/DateTimeFormatter.php +++ b/lib/private/DateTimeFormatter.php @@ -125,7 +125,7 @@ public function formatDate($timestamp, $format = 'long', \DateTimeZone $timeZone * @return string Formatted relative date string */ public function formatDateRelativeDay($timestamp, $format = 'long', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { - if (substr($format, -1) !== '*' && substr($format, -1) !== '*') { + if (!str_ends_with($format, '^') && !str_ends_with($format, '*')) { $format .= '^'; } @@ -289,7 +289,7 @@ public function formatDateTime($timestamp, $formatDate = 'long', $formatTime = ' * @return string Formatted relative date and time string */ public function formatDateTimeRelativeDay($timestamp, $formatDate = 'long', $formatTime = 'medium', \DateTimeZone $timeZone = null, \OCP\IL10N $l = null) { - if (substr($formatDate, -1) !== '^' && substr($formatDate, -1) !== '*') { + if (!str_ends_with($formatDate, '^') && !str_ends_with($formatDate, '*')) { $formatDate .= '^'; } diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php index 70f22a1703400..2d2bb52635be1 100644 --- a/lib/private/Files/Storage/DAV.php +++ b/lib/private/Files/Storage/DAV.php @@ -120,9 +120,9 @@ public function __construct($params) { if (isset($params['host']) && isset($params['user']) && isset($params['password'])) { $host = $params['host']; //remove leading http[s], will be generated in createBaseUri() - if (substr($host, 0, 8) == "https://") { + if (str_starts_with($host, "https://")) { $host = substr($host, 8); - } elseif (substr($host, 0, 7) == "http://") { + } elseif (str_starts_with($host, "http://")) { $host = substr($host, 7); } $this->host = $host; diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index c0ce0e7021a4e..5515f5b1564aa 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -85,7 +85,7 @@ public function __construct($arguments) { $realPath = realpath($this->datadir) ?: $this->datadir; $this->realDataDir = rtrim($realPath, '/') . '/'; } - if (substr($this->datadir, -1) !== '/') { + if (!str_ends_with($this->datadir, '/')) { $this->datadir .= '/'; } $this->dataDirLength = strlen($this->realDataDir); @@ -155,7 +155,7 @@ public function opendir($path) { } public function is_dir($path) { - if (substr($path, -1) == '/') { + if (str_ends_with($path, '/')) { $path = substr($path, 0, -1); } return is_dir($this->getSourcePath($path)); diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php index 778124c4c3854..f7d3fec4ff67b 100644 --- a/lib/private/L10N/Factory.php +++ b/lib/private/L10N/Factory.php @@ -358,7 +358,7 @@ public function findAvailableLanguages($app = null): array { $files = scandir($dir); if ($files !== false) { foreach ($files as $file) { - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { + if (str_ends_with($file, '.json') && !str_starts_with($file, 'l10n')) { $available[] = substr($file, 0, -5); } } @@ -374,7 +374,7 @@ public function findAvailableLanguages($app = null): array { $files = scandir($themeDir); if ($files !== false) { foreach ($files as $file) { - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { + if (str_ends_with($file, '.json') && !str_starts_with($file, 'l10n')) { $available[] = substr($file, 0, -5); } } diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index fe97623176d0c..5ce6c7c5c8f49 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -247,23 +247,23 @@ public function create($name, */ public function findMatchingRoute(string $url): array { $this->eventLogger->start('route:match', 'Match route'); - if (substr($url, 0, 6) === '/apps/') { + if (str_starts_with($url, '/apps/')) { // empty string / 'apps' / $app / rest of the route [, , $app,] = explode('/', $url, 4); $app = \OC_App::cleanAppId($app); \OC::$REQUESTEDAPP = $app; $this->loadRoutes($app); - } elseif (substr($url, 0, 13) === '/ocsapp/apps/') { + } elseif (str_starts_with($url, '/ocsapp/apps/')) { // empty string / 'ocsapp' / 'apps' / $app / rest of the route [, , , $app,] = explode('/', $url, 5); $app = \OC_App::cleanAppId($app); \OC::$REQUESTEDAPP = $app; $this->loadRoutes($app); - } elseif (substr($url, 0, 10) === '/settings/') { + } elseif (str_starts_with($url, '/settings/')) { $this->loadRoutes('settings'); - } elseif (substr($url, 0, 6) === '/core/') { + } elseif (str_starts_with($url, '/core/')) { \OC::$REQUESTEDAPP = $url; if (!$this->config->getSystemValueBool('maintenance') && !Util::needUpgrade()) { \OC_App::loadApps(); @@ -277,7 +277,7 @@ public function findMatchingRoute(string $url): array { try { $parameters = $matcher->match($url); } catch (ResourceNotFoundException $e) { - if (substr($url, -1) !== '/') { + if (!str_ends_with($url, '/')) { // We allow links to apps/files? for backwards compatibility reasons // However, since Symfony does not allow empty route names, the route // we need to match is '/', so we need to append the '/' here. diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 658a85152bf49..cefa1f308767a 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -279,7 +279,7 @@ public function __construct($renderAs, $appId = '') { $web = $info[1]; $file = $info[2]; - if (substr($file, -strlen('print.css')) === 'print.css') { + if (str_ends_with($file, 'print.css')) { $this->append('printcssfiles', $web.'/'.$file . $this->getVersionHashSuffix()); } else { $suffix = $this->getVersionHashSuffix($web, $file); diff --git a/lib/private/URLGenerator.php b/lib/private/URLGenerator.php index 3a52b99889c05..57bafc3e18dae 100644 --- a/lib/private/URLGenerator.php +++ b/lib/private/URLGenerator.php @@ -147,7 +147,7 @@ public function linkTo(string $appName, string $file, array $args = []): string $app_path = $this->getAppManager()->getAppPath($appName); // Check if the app is in the app folder if (file_exists($app_path . '/' . $file)) { - if (substr($file, -3) === 'php') { + if (str_ends_with($file, 'php')) { $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $appName; if ($frontControllerActive) { $urlLinkTo = \OC::$WEBROOT . '/apps/' . $appName; diff --git a/lib/private/User/User.php b/lib/private/User/User.php index dc4cdec1235b0..e57b71b177872 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -610,7 +610,7 @@ public function getAvatarImage($size) { public function getCloudId() { $uid = $this->getUID(); $server = rtrim($this->urlGenerator->getAbsoluteURL('/'), '/'); - if (substr($server, -10) === '/index.php') { + if (str_ends_with($server, '/index.php')) { $server = substr($server, 0, -10); } $server = $this->removeProtocolFromUrl($server); diff --git a/lib/private/legacy/OC_API.php b/lib/private/legacy/OC_API.php index 275e02986c4b2..862e73e6edd0e 100644 --- a/lib/private/legacy/OC_API.php +++ b/lib/private/legacy/OC_API.php @@ -130,7 +130,7 @@ public static function setContentType($format = null) { protected static function isV2(\OCP\IRequest $request) { $script = $request->getScriptName(); - return substr($script, -11) === '/ocs/v2.php'; + return str_ends_with($script, '/ocs/v2.php'); } /**