diff --git a/apps/files_external/lib/Lib/Storage/OwnCloud.php b/apps/files_external/lib/Lib/Storage/OwnCloud.php
index d846fa811a02a8ececf04084f8c724d061bfa487..d56e6b66145f800f23f85e18f651957b65efd984 100644
--- a/apps/files_external/lib/Lib/Storage/OwnCloud.php
+++ b/apps/files_external/lib/Lib/Storage/OwnCloud.php
@@ -61,10 +61,7 @@ class OwnCloud extends \OC\Files\Storage\DAV{
 		}
 
 		if (isset($params['root'])){
-			$root = $params['root'];
-			if (substr($root, 0, 1) !== '/'){
-				$root = '/' . $root;
-			}
+			$root = '/' . ltrim($params['root'], '/');
 		}
 		else{
 			$root = '/';
diff --git a/apps/files_external/lib/Lib/Storage/SFTP.php b/apps/files_external/lib/Lib/Storage/SFTP.php
index 22162fa61cf4ea99c4f0958914dc25a79cf849e8..6bd77dd2496ef9dd86e9221e462731583586e568 100644
--- a/apps/files_external/lib/Lib/Storage/SFTP.php
+++ b/apps/files_external/lib/Lib/Storage/SFTP.php
@@ -103,13 +103,8 @@ class SFTP extends \OC\Files\Storage\Common {
 		$this->root
 			= isset($params['root']) ? $this->cleanPath($params['root']) : '/';
 
-		if ($this->root[0] !== '/') {
-			 $this->root = '/' . $this->root;
-		}
-
-		if (substr($this->root, -1, 1) !== '/') {
-			$this->root .= '/';
-		}
+		$this->root = '/' . ltrim($this->root, '/');
+		$this->root = rtrim($this->root, '/') . '/';
 	}
 
 	/**
diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php
index d8bbe8c47181a83174b12238b4aff9eea79fb9c5..58a6f65990fe41566de91f4c2594916318f9928e 100644
--- a/apps/files_external/lib/Lib/Storage/SMB.php
+++ b/apps/files_external/lib/Lib/Storage/SMB.php
@@ -84,13 +84,9 @@ class SMB extends Common implements INotifyStorage {
 			}
 			$this->share = $this->server->getShare(trim($params['share'], '/'));
 
-			$this->root = isset($params['root']) ? $params['root'] : '/';
-			if (!$this->root || $this->root[0] !== '/') {
-				$this->root = '/' . $this->root;
-			}
-			if (substr($this->root, -1, 1) !== '/') {
-				$this->root .= '/';
-			}
+			$this->root = $params['root'] ?? '/';
+			$this->root = '/' . ltrim($this->root, '/');
+			$this->root = rtrim($this->root, '/') . '/';
 		} else {
 			throw new \Exception('Invalid configuration');
 		}
diff --git a/lib/private/App/AppStore/Version/VersionParser.php b/lib/private/App/AppStore/Version/VersionParser.php
index 3924b8aea16a4b1cdef62865e5991ce1c02e7b6d..cdbb62ffbc553e256c564cd35f43590e3da2e50b 100644
--- a/lib/private/App/AppStore/Version/VersionParser.php
+++ b/lib/private/App/AppStore/Version/VersionParser.php
@@ -63,11 +63,10 @@ class VersionParser {
 				if(!$this->isValidVersionString($firstVersionNumber)) {
 					break;
 				}
-				if(substr($firstVersion, 0, 1) === '>') {
+				if(strpos($firstVersion, '>') === 0) {
 					return new Version($firstVersionNumber, '');
-				} else {
-					return new Version('', $firstVersionNumber);
 				}
+				return new Version('', $firstVersionNumber);
 			case 2:
 				if(!$this->isValidVersionString($firstVersionNumber) || !$this->isValidVersionString($secondVersionNumber)) {
 					break;
diff --git a/lib/private/Archive/TAR.php b/lib/private/Archive/TAR.php
index 2c34125afe6e1dc648877c51629bbb200dd4b385..f37da6fc52d0bc25a605f0cadd1209d77bb4e2f1 100644
--- a/lib/private/Archive/TAR.php
+++ b/lib/private/Archive/TAR.php
@@ -91,9 +91,7 @@ class TAR extends Archive {
 	 */
 	public function addFolder($path) {
 		$tmpBase = \OC::$server->getTempManager()->getTemporaryFolder();
-		if (substr($path, -1, 1) != '/') {
-			$path .= '/';
-		}
+		$path = rtrim($path, '/') . '/';
 		if ($this->fileExists($path)) {
 			return false;
 		}
@@ -297,10 +295,7 @@ class TAR extends Archive {
 		if ((array_search($path, $files) !== false) or (array_search($path . '/', $files) !== false)) {
 			return true;
 		} else {
-			$folderPath = $path;
-			if (substr($folderPath, -1, 1) != '/') {
-				$folderPath .= '/';
-			}
+			$folderPath = rtrim($path, '/') . '/';
 			$pathLength = strlen($folderPath);
 			foreach ($files as $file) {
 				if (strlen($file) > $pathLength and substr($file, 0, $pathLength) == $folderPath) {
diff --git a/lib/private/Avatar.php b/lib/private/Avatar.php
index b3df607a32b004e62729161e233639d71148c5ab..4cacc801689c44f514b4e29f43fb88d8ec50c38c 100644
--- a/lib/private/Avatar.php
+++ b/lib/private/Avatar.php
@@ -263,7 +263,7 @@ class Avatar implements IAvatar {
 	 * @return string
 	 */
 	private function generateAvatar($userDisplayName, $size) {
-		$text = strtoupper(substr($userDisplayName, 0, 1));
+		$text = strtoupper($userDisplayName[0]);
 		$backgroundColor = $this->avatarBackgroundColor($userDisplayName);
 
 		$im = imagecreatetruecolor($size, $size);
diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php
index caf23afba117561432e5c061f7e46c6f759e2672..95703eab925b7a71fd1347c2900b064602d62263 100644
--- a/lib/private/Files/Filesystem.php
+++ b/lib/private/Files/Filesystem.php
@@ -839,8 +839,8 @@ class Filesystem {
 		$path = preg_replace('#/{2,}#', '/', $path);
 
 		//remove trailing slash
-		if ($stripTrailingSlash and strlen($path) > 1 and substr($path, -1, 1) === '/') {
-			$path = substr($path, 0, -1);
+		if ($stripTrailingSlash and strlen($path) > 1) {
+			$path = rtrim($path, '/');
 		}
 
 		// remove trailing '/.'
diff --git a/lib/private/Files/Storage/DAV.php b/lib/private/Files/Storage/DAV.php
index 43347aa0b8fd7018de4c833a8d76a476eb1fa152..f9c6175308cadafe1303aeb1b3b24ff51e2aec4b 100644
--- a/lib/private/Files/Storage/DAV.php
+++ b/lib/private/Files/Storage/DAV.php
@@ -118,13 +118,9 @@ class DAV extends Common {
 					$this->certPath = $certPath;
 				}
 			}
-			$this->root = isset($params['root']) ? $params['root'] : '/';
-			if (!$this->root || $this->root[0] != '/') {
-				$this->root = '/' . $this->root;
-			}
-			if (substr($this->root, -1, 1) != '/') {
-				$this->root .= '/';
-			}
+			$this->root = $params['root'] ?? '/';
+			$this->root = '/' . ltrim($this->root, '/');
+			$this->root = rtrim($this->root, '/') . '/';
 		} else {
 			throw new \Exception('Invalid webdav storage configuration');
 		}
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index fb0b116666ee423c2a9ab20d2e536c0251924c77..1553444e05d2f4abb609dbfd5db6fff93664579b 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -698,7 +698,7 @@ class View {
 			// do not allow deleting the root
 			return false;
 		}
-		$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
+		$postFix = (substr($path, -1) === '/') ? '/' : '';
 		$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
 		$mount = Filesystem::getMountManager()->find($absolutePath . $postFix);
 		if ($mount and $mount->getInternalPath($absolutePath) === '') {
@@ -1067,7 +1067,7 @@ class View {
 	 * @return bool|null|string
 	 */
 	public function hash($type, $path, $raw = false) {
-		$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
+		$postFix = (substr($path, -1) === '/') ? '/' : '';
 		$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
 		if (Filesystem::isValidPath($path)) {
 			$path = $this->getRelativePath($absolutePath);
@@ -1119,7 +1119,7 @@ class View {
 	 * \OC\Files\Storage\Storage for delegation to a storage backend for execution
 	 */
 	private function basicOperation($operation, $path, $hooks = [], $extraParam = null) {
-		$postFix = (substr($path, -1, 1) === '/') ? '/' : '';
+		$postFix = (substr($path, -1) === '/') ? '/' : '';
 		$absolutePath = Filesystem::normalizePath($this->getAbsolutePath($path));
 		if (Filesystem::isValidPath($path)
 			and !Filesystem::isFileBlacklisted($path)
diff --git a/lib/private/Installer.php b/lib/private/Installer.php
index ed654c2b241e35734f42a06d4f4bb6ce6fcd6cbb..ea8ee5f01e5a3930447bf8973f477039eb0c4db8 100644
--- a/lib/private/Installer.php
+++ b/lib/private/Installer.php
@@ -519,7 +519,7 @@ class Installer {
 		foreach(\OC::$APPSROOTS as $app_dir) {
 			if($dir = opendir( $app_dir['path'] )) {
 				while( false !== ( $filename = readdir( $dir ))) {
-					if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) {
+					if( $filename[0] !== '.' and is_dir($app_dir['path']."/$filename") ) {
 						if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
 							if(!Installer::isInstalled($filename)) {
 								$info=OC_App::getAppInfo($filename);
diff --git a/lib/private/Settings/Personal/PersonalInfo.php b/lib/private/Settings/Personal/PersonalInfo.php
index dbc05cbda2fa5d4e84e445b1e1c9c70c7f7c6c1d..ad277b431942310028431995599922f3674bb897 100644
--- a/lib/private/Settings/Personal/PersonalInfo.php
+++ b/lib/private/Settings/Personal/PersonalInfo.php
@@ -208,7 +208,7 @@ class PersonalInfo implements ISettings {
 			$l = \OC::$server->getL10N('settings', $lang);
 			// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
 			$potentialName = (string) $l->t('__language_name__');
-			if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file
+			if($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file
 				$ln = array('code' => $lang, 'name' => $potentialName);
 			} elseif ($lang === 'en') {
 				$ln = ['code' => $lang, 'name' => 'English (US)'];
diff --git a/lib/private/legacy/image.php b/lib/private/legacy/image.php
index 6ad9426a71777de173b1b42bd473a7725bbf5bd9..eeee3b24073347c5b8c8674a735d2876dd32493b 100644
--- a/lib/private/legacy/image.php
+++ b/lib/private/legacy/image.php
@@ -784,16 +784,16 @@ class OC_Image implements \OCP\IImage {
 						$color[1] = (($color[1] & 0xf800) >> 8) * 65536 + (($color[1] & 0x07e0) >> 3) * 256 + (($color[1] & 0x001f) << 3);
 						break;
 					case 8:
-						$color = @unpack('n', $vide . substr($data, $p, 1));
+						$color = @unpack('n', $vide . ($data[$p] ?? ''));
 						$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
 						break;
 					case 4:
-						$color = @unpack('n', $vide . substr($data, floor($p), 1));
+						$color = @unpack('n', $vide . ($data[floor($p)] ?? ''));
 						$color[1] = ($p * 2) % 2 == 0 ? $color[1] >> 4 : $color[1] & 0x0F;
 						$color[1] = (isset($palette[$color[1] + 1])) ? $palette[$color[1] + 1] : $palette[1];
 						break;
 					case 1:
-						$color = @unpack('n', $vide . substr($data, floor($p), 1));
+						$color = @unpack('n', $vide . ($data[floor($p)] ?? ''));
 						switch (($p * 8) % 8) {
 							case 0:
 								$color[1] = $color[1] >> 7;