diff options
author | Faraz Samapoor <fsamapoor@gmail.com> | 2023-05-15 15:17:19 +0330 |
---|---|---|
committer | Faraz Samapoor <fsamapoor@gmail.com> | 2023-05-15 15:17:19 +0330 |
commit | e7cc7653b885c49b1b3f0a78f91ea05a53e102d8 (patch) | |
tree | 42da61d5c6e988d7c9eff7e081327a73f661dc89 /lib/private/AppFramework/Http | |
parent | 8bdb50fd507bfe68161ab98eba903872083ea4f3 (diff) | |
download | nextcloud-server-e7cc7653b885c49b1b3f0a78f91ea05a53e102d8.tar.gz nextcloud-server-e7cc7653b885c49b1b3f0a78f91ea05a53e102d8.zip |
Refactors "strpos" calls in lib/private to improve code readability.
Signed-off-by: Faraz Samapoor <fsamapoor@gmail.com>
Diffstat (limited to 'lib/private/AppFramework/Http')
-rw-r--r-- | lib/private/AppFramework/Http/Dispatcher.php | 4 | ||||
-rw-r--r-- | lib/private/AppFramework/Http/Request.php | 18 |
2 files changed, 11 insertions, 11 deletions
diff --git a/lib/private/AppFramework/Http/Dispatcher.php b/lib/private/AppFramework/Http/Dispatcher.php index b4b03574d56..13b391eb287 100644 --- a/lib/private/AppFramework/Http/Dispatcher.php +++ b/lib/private/AppFramework/Http/Dispatcher.php @@ -212,8 +212,8 @@ class Dispatcher { $value === 'false' && ( $this->request->method === 'GET' || - strpos($this->request->getHeader('Content-Type'), - 'application/x-www-form-urlencoded') !== false + str_contains($this->request->getHeader('Content-Type'), + 'application/x-www-form-urlencoded') ) ) { $value = false; diff --git a/lib/private/AppFramework/Http/Request.php b/lib/private/AppFramework/Http/Request.php index 52abb909b60..408e88583a0 100644 --- a/lib/private/AppFramework/Http/Request.php +++ b/lib/private/AppFramework/Http/Request.php @@ -413,8 +413,8 @@ class Request implements \ArrayAccess, \Countable, IRequest { return $this->method === 'PUT' && $this->getHeader('Content-Length') !== '0' && $this->getHeader('Content-Length') !== '' - && strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') === false - && strpos($this->getHeader('Content-Type'), 'application/json') === false; + && !str_contains($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') + && !str_contains($this->getHeader('Content-Type'), 'application/json'); } /** @@ -439,7 +439,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { // or post correctly } elseif ($this->method !== 'GET' && $this->method !== 'POST' - && strpos($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded') !== false) { + && str_contains($this->getHeader('Content-Type'), 'application/x-www-form-urlencoded')) { parse_str(file_get_contents($this->inputStream), $params); if (\is_array($params)) { $this->items['params'] = $params; @@ -603,7 +603,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { $IP = trim($IP); // remove brackets from IPv6 addresses - if (strpos($IP, '[') === 0 && substr($IP, -1) === ']') { + if (str_starts_with($IP, '[') && str_ends_with($IP, ']')) { $IP = substr($IP, 1, -1); } @@ -642,7 +642,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { } if ($this->fromTrustedProxy() && isset($this->server['HTTP_X_FORWARDED_PROTO'])) { - if (strpos($this->server['HTTP_X_FORWARDED_PROTO'], ',') !== false) { + if (str_contains($this->server['HTTP_X_FORWARDED_PROTO'], ',')) { $parts = explode(',', $this->server['HTTP_X_FORWARDED_PROTO']); $proto = strtolower(trim($parts[0])); } else { @@ -724,7 +724,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { // FIXME: Sabre does not really belong here [$path, $name] = \Sabre\Uri\split($scriptName); if (!empty($path)) { - if ($path === $pathInfo || strpos($pathInfo, $path.'/') === 0) { + if ($path === $pathInfo || str_starts_with($pathInfo, $path . '/')) { $pathInfo = substr($pathInfo, \strlen($path)); } else { throw new \Exception("The requested uri($requestUri) cannot be processed by the script '$scriptName')"); @@ -734,10 +734,10 @@ class Request implements \ArrayAccess, \Countable, IRequest { $name = ''; } - if (strpos($pathInfo, '/'.$name) === 0) { + if (str_starts_with($pathInfo, '/' . $name)) { $pathInfo = substr($pathInfo, \strlen($name) + 1); } - if ($name !== '' && strpos($pathInfo, $name) === 0) { + if ($name !== '' && str_starts_with($pathInfo, $name)) { $pathInfo = substr($pathInfo, \strlen($name)); } if ($pathInfo === false || $pathInfo === '/') { @@ -803,7 +803,7 @@ class Request implements \ArrayAccess, \Countable, IRequest { $host = 'localhost'; if ($this->fromTrustedProxy() && isset($this->server['HTTP_X_FORWARDED_HOST'])) { - if (strpos($this->server['HTTP_X_FORWARDED_HOST'], ',') !== false) { + if (str_contains($this->server['HTTP_X_FORWARDED_HOST'], ',')) { $parts = explode(',', $this->server['HTTP_X_FORWARDED_HOST']); $host = trim(current($parts)); } else { |