Refactors "strpos" calls in /core to improve code readability.

Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
pull/38602/head
Faraz Samapoor 2 years ago
parent 09c5f997c6
commit a1ef0285f8
  1. 4
      core/Controller/ClientFlowLoginController.php
  2. 4
      core/Controller/ClientFlowLoginV2Controller.php
  3. 2
      core/Controller/CssController.php
  4. 2
      core/Controller/JsController.php
  5. 2
      core/Controller/LoginController.php
  6. 4
      core/Controller/NavigationController.php
  7. 2
      core/ajax/update.php

@ -368,9 +368,9 @@ class ClientFlowLoginController extends Controller {
private function getServerPath(): string { private function getServerPath(): string {
$serverPostfix = ''; $serverPostfix = '';
if (strpos($this->request->getRequestUri(), '/index.php') !== false) { if (str_contains($this->request->getRequestUri(), '/index.php')) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php')); $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
} elseif (strpos($this->request->getRequestUri(), '/login/flow') !== false) { } elseif (str_contains($this->request->getRequestUri(), '/login/flow')) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow')); $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
} }

@ -363,9 +363,9 @@ class ClientFlowLoginV2Controller extends Controller {
private function getServerPath(): string { private function getServerPath(): string {
$serverPostfix = ''; $serverPostfix = '';
if (strpos($this->request->getRequestUri(), '/index.php') !== false) { if (str_contains($this->request->getRequestUri(), '/index.php')) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php')); $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
} elseif (strpos($this->request->getRequestUri(), '/login/v2') !== false) { } elseif (str_contains($this->request->getRequestUri(), '/login/v2')) {
$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/v2')); $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/v2'));
} }

@ -101,7 +101,7 @@ class CssController extends Controller {
private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile { private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile {
$encoding = $this->request->getHeader('Accept-Encoding'); $encoding = $this->request->getHeader('Accept-Encoding');
if (strpos($encoding, 'gzip') !== false) { if (str_contains($encoding, 'gzip')) {
try { try {
$gzip = true; $gzip = true;
return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz

@ -99,7 +99,7 @@ class JsController extends Controller {
private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile { private function getFile(ISimpleFolder $folder, string $fileName, bool &$gzip): ISimpleFile {
$encoding = $this->request->getHeader('Accept-Encoding'); $encoding = $this->request->getHeader('Accept-Encoding');
if (strpos($encoding, 'gzip') !== false) { if (str_contains($encoding, 'gzip')) {
try { try {
$gzip = true; $gzip = true;
return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz return $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz

@ -275,7 +275,7 @@ class LoginController extends Controller {
$location = $this->urlGenerator->getAbsoluteURL($redirectUrl); $location = $this->urlGenerator->getAbsoluteURL($redirectUrl);
// Deny the redirect if the URL contains a @ // Deny the redirect if the URL contains a @
// This prevents unvalidated redirects like ?redirect_url=:user@domain.com // This prevents unvalidated redirects like ?redirect_url=:user@domain.com
if (strpos($location, '@') === false) { if (!str_contains($location, '@')) {
return new RedirectResponse($location); return new RedirectResponse($location);
} }
} }

@ -94,10 +94,10 @@ class NavigationController extends OCSController {
*/ */
private function rewriteToAbsoluteUrls(array $navigation): array { private function rewriteToAbsoluteUrls(array $navigation): array {
foreach ($navigation as &$entry) { foreach ($navigation as &$entry) {
if (0 !== strpos($entry['href'], $this->urlGenerator->getBaseUrl())) { if (!str_starts_with($entry['href'], $this->urlGenerator->getBaseUrl())) {
$entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']); $entry['href'] = $this->urlGenerator->getAbsoluteURL($entry['href']);
} }
if (0 !== strpos($entry['icon'], $this->urlGenerator->getBaseUrl())) { if (!str_starts_with($entry['icon'], $this->urlGenerator->getBaseUrl())) {
$entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']); $entry['icon'] = $this->urlGenerator->getAbsoluteURL($entry['icon']);
} }
} }

@ -44,7 +44,7 @@ use OC\Repair\Events\RepairStartEvent;
use OC\Repair\Events\RepairStepEvent; use OC\Repair\Events\RepairStepEvent;
use OC\Repair\Events\RepairWarningEvent; use OC\Repair\Events\RepairWarningEvent;
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
@set_time_limit(0); @set_time_limit(0);
} }

Loading…
Cancel
Save